Re: add line number as prompt option to psql

From: Sawada Masahiko <sawada(dot)mshk(at)gmail(dot)com>
To: Jeevan Chalke <jeevan(dot)chalke(at)enterprisedb(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 13:53:33
Message-ID: CAD21AoCzfte7h2-xpzmv0BQffU3+QomhKjpMm5b_cRxW5eE4mA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jul 10, 2014 at 8:35 PM, Jeevan Chalke
<jeevan(dot)chalke(at)enterprisedb(dot)com> wrote:
> 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.
>

Thank you for reviewing the patch with variable cases.
I have revised the patch, and attached latest patch.

> A:
> Will you please explain the idea behind these changes ?
I thought wrong about adding new to tail of query_buf.
The latest patch does not change related to them.

> B:
I added the condition of cur_line < 0.

Regards,

-------
Sawada Masahiko

Attachment Content-Type Size
psql-line-number_v4.patch application/octet-stream 3.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Sawada Masahiko 2014-07-10 14:10:38 timeout of pg_receivexlog --status-interval
Previous Message Andrew Dunstan 2014-07-10 13:15:00 Re: Missing IPv6 for pgbuildfarm.org