Re: add line number as prompt option to psql

From: Sawada Masahiko <sawada(dot)mshk(at)gmail(dot)com>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: Jeevan Chalke <jeevan(dot)chalke(at)enterprisedb(dot)com>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: add line number as prompt option to psql
Date: 2014-09-02 03:34:12
Message-ID: CAD21AoBf-u3R-LY7VXBrLrcs-23N1KaaSBaHYXQ9dRgKo-TXuw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Sep 2, 2014 at 11:12 AM, Andres Freund <andres(at)2ndquadrant(dot)com> wrote:
> On 2014-08-31 12:06:31 +0900, Sawada Masahiko wrote:
>> Thank you for review comment and improving the patch!
>> I tested it.
>> Your patch always increment line number even if there is no input line
>> as follows.
>>
>> postgres[1]=#
>> postgres[2]=# select
>> postgres[3]-# ,
>> postgres[4]-# from
>> postgres[5]-# hoge;
>> ERROR: syntax error at or near "," at character 8
>> STATEMENT: select
>> ,
>> from
>> hoge;
>> ERROR: syntax error at or near ","
>> LINE 2: ,
>> ^
>> Actually error syntax is in line 2 as postgres reported.
>> But it is inconsistent.
>
> Hm. Right. That's clearly wrong.
>
>> Attached patch is resolve above behavior based on your version patch.
>
> I've looked a bit further and found two more broken things.
>
> 1)
> postgres[1]=# SELECT 1; SELECT 2
> postgres[1]=#
>
> Note the 1 in the second line. Obviously wrong.
>
> The fix for this is easy: Don't count a newline if there isn't one. But
> check for PSCAN_EOL. That also gets rid of inconsistent pset.stmt_lineno
> initializations (sometimes to 0, sometimes to 1).
>
> 2)
> postgres[1]=# SELECT 1,
> postgres[2]-# 2,
> postgres[3]-# 3;
> ┌──────────┬──────────┬──────────┐
> │ ?column? │ ?column? │ ?column? │
> ├──────────┼──────────┼──────────┤
> │ 1 │ 2 │ 3 │
> └──────────┴──────────┴──────────┘
> (1 row)
>
> postgres[1]=# SELECT 1,
> 2,
> 3;
> ┌──────────┬──────────┬──────────┐
> │ ?column? │ ?column? │ ?column? │
> ├──────────┼──────────┼──────────┤
> │ 1 │ 2 │ 3 │
> └──────────┴──────────┴──────────┘
> (1 row)
>
> postgres[3]=#
>
> Obviously the three in the last line is wrong.
>
> The fix is slightly nontrivial. It's wrong to look at 'line' when
> determining the number of lines to add - it may already be
> executed. The, it seems to me, correct thing is to look at the data
> that's appended to the query buffer. Alternatively we could always count
> all lines in the query buffer, but that'd be O(lines^2)...
>
>
> I've done both in the appended patch.
>
>
> I've now used up a perfectly good glass of wine for this, so this is it
> for today ;)
>

Thank you for updating the patch!
I tested it.
These fix looks good to me :)

Regards,

-------
Sawada Masahiko

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Craig Ringer 2014-09-02 03:41:00 Re: PL/pgSQL 2
Previous Message Craig Ringer 2014-09-02 03:24:35 Re: PL/pgSQL 2