Re: add line number as prompt option to psql

From: Jeevan Chalke <jeevan(dot)chalke(at)enterprisedb(dot)com>
To: Sawada Masahiko <sawada(dot)mshk(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: add line number as prompt option to psql
Date: 2014-07-10 11:35:23
Message-ID: CAM2+6=VgWpZFxgoA5uujYwSOKc9sBy7GRAVd5=dOPrpG4MAD1w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Found few more bugs in new code:

A:
This got bad:

jeevan(at)ubuntu:~/pg_master$ ./install/bin/psql postgres
psql (9.5devel)
Type "help" for help.

postgres=# \set PROMPT1 '%/[%l]%R%# '
postgres[1]=# \set PROMPT2 '%/[%l]%R%# '
postgres[1]=# select
postgres[2]-# *
postgres[3]-# from
postgres[4]-# abc;
ERROR: syntax error at or near "fromabc"
LINE 1: select*fromabc;
^
postgres[1]=#
postgres[1]=#
postgres[1]=# \e
ERROR: syntax error at or near "fromabc"
LINE 1: select*fromabc;
^
postgres[1]=# select*fromabc;
ERROR: syntax error at or near "fromabc"
LINE 1: select*fromabc;
^
postgres[1]=#

See query text in LINE 1:. This is because, you have removed addition of
newline character. Related added_nl_pos. Need more investigation here.
However I don't think these changes are relevant to what you wanted in this
feature.
Will you please explain the idea behind these changes ?

Moreover, if you don't want to add newline character, then I guess entire
logic related to added_nl_pos is NO more required. You may remove this
variable and its logic altogether, not sure though. Also make sure you
update the relevant comments while doing so. Here you have removed the code
which is adding the newline but the comment there still reads:
/* insert newlines into query buffer between source lines */

Need more thoughts on this.

B:
postgres=# \set PROMPT1 '%/[%l]%R%# '
postgres[1]=# \set PROMPT2 '%/[%l]%R%# '
postgres[1]=# \e
postgres[-2147483645]-# limit 1;
relname
--------------
pg_statistic
(1 row)

postgres[1]=#
postgres[1]=# select
relname
from
pg_class
limit 1;

Logic related to wrapping around the cur_line counter is wrong. Actually
issue is with newline variable. If number of lines in \e editor goes beyond
INT_MAX (NOT sure about the practical use), then newline will be -ve which
then enforces cur_line to be negative. To mimic this I have initialized
newline = INT_MAX - 1.

Thanks

--
Jeevan B Chalke
Principal Software Engineer, Product Development
EnterpriseDB Corporation
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2014-07-10 12:56:53 Re: psql: show only failed queries
Previous Message Guillaume Lelarge 2014-07-10 11:11:31 Re: Re: how to find the order of joins from Explain command XML plan output in PostgreSQL