Re: add line number as prompt option to psql - Mailing list pgsql-hackers
From | Sawada Masahiko |
---|---|
Subject | Re: add line number as prompt option to psql |
Date | |
Msg-id | CAD21AoApS4B7vqs4xu7fc9c8kmvy0MeUuU4quJfioqm8jYDn3g@mail.gmail.com Whole thread Raw |
In response to | Re: add line number as prompt option to psql (Andres Freund <andres@2ndquadrant.com>) |
Responses |
Re: add line number as prompt option to psql
|
List | pgsql-hackers |
On Tue, Aug 26, 2014 at 10:23 PM, Andres Freund <andres@2ndquadrant.com> wrote: > On 2014-08-21 11:43:48 +0900, Sawada Masahiko wrote: >> On Wed, Aug 20, 2014 at 9:00 PM, Jeevan Chalke >> <jeevan.chalke@enterprisedb.com> wrote: >> > Hi, >> > >> > I have reviewed this: >> > >> > I have initialize cur_lineno to UINTMAX - 2. And then observed following >> > behaviour to check wrap-around. >> > >> > postgres=# \set PROMPT1 '%/[%l]%R%# ' >> > postgres[18446744073709551613]=# \set PROMPT2 '%/[%l]%R%# ' >> > postgres[18446744073709551613]=# select >> > postgres[18446744073709551614]-# a >> > postgres[18446744073709551615]-# , >> > postgres[0]-# b >> > postgres[1]-# from >> > postgres[2]-# dual; >> > >> > It is wrapping to 0, where as line number always start with 1. Any issues? >> > >> > I would like to ignore this as UINTMAX lines are too much for a input >> > buffer to hold. It is almost NIL chances to hit this. >> > >> > >> > However, I think you need to use UINT64_FORMAT while printing uint64 >> > number. Currently it is %u which wrap-around at UINT_MAX. >> > See how pset.lineno is displayed. >> > >> > Apart from this, I didn't see any issues in my testing. >> > >> > Patch applies cleanly. make/make install/initdb/make check all are well. >> > >> >> Thank you for reviewing the patch! >> Attached patch is latest version patch. >> I modified the output format of cur_lineno. > > I like the feature - and I wanted to commit it, but enough stuff turned > up that I needed to fix that it warrants some new testing. > > Stuff I've changed: > * removed include of limits.h - that probably was a rememnant from a > previous version > * removed a trailing whitespace > * expanded the documentation about %l. "The current line number" isn't > very clear. Of a file? Of all lines ever entered in psql? It's now > "The line number inside the current statement, starting from > <literal>1</>." > * Correspondingly I've changed the variable's name to stmt_lineno. > * COPY FROM ... STDIN/PROMPT3 was broken because a) the promp was only generated > once b) the lineno wasn't incremented. > * CTRL-C didn't reset the line number. > * Unfortunately I've notice here that the prompting is broken in some > common cases: > > postgres[1]=# SELECT 1, > postgres[2]-# '2 > postgres[2]'# 2b > postgres[2]'# 2c > postgres[2]'# 2d', > postgres[3]-# 3; > ┌──────────┬──────────┬──────────┐ > │ ?column? │ ?column? │ ?column? │ > ├──────────┼──────────┼──────────┤ > │ 1 │ 2 ↵│ 3 │ > │ │ 2b ↵│ │ > │ │ 2c ↵│ │ > │ │ 2d │ │ > └──────────┴──────────┴──────────┘ > (1 row) > > postgres[1]=# SELECT 1, > '2 > 2b > 2c > 2d', > 3 > postgres[7]-# > > That's rather inconsistent... > > > I've attached my version of the patch. Note that I've got rid of all the > PSCAN_INCOMPLETE checks... Please test! > 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. Attached patch is resolve above behavior based on your version patch. Regards, ------- Sawada Masahiko
Attachment
pgsql-hackers by date: