Re: add line number as prompt option to psql - Mailing list pgsql-hackers

From Jeevan Chalke
Subject Re: add line number as prompt option to psql
Date
Msg-id CAM2+6=Wwc=yq78hjBBtx8oUO+-dRqE7suR_OvJ7525wDr31_qg@mail.gmail.com
Whole thread Raw
In response to Re: add line number as prompt option to psql  (Sawada Masahiko <sawada.mshk@gmail.com>)
Responses Re: add line number as prompt option to psql  (Sawada Masahiko <sawada.mshk@gmail.com>)
List pgsql-hackers
<div dir="ltr">Hi,<br /><br />Found two (A and B) issues with latest patch:<br /><br />A:<br />-- Set prompts<br
/>postgres=#\set PROMPT1 '%/[%l]%R%# '<br />postgres[1]=# \set PROMPT2 '%/[%l]%R%# '<br /><br />postgres[1]=# <br />
postgres[1]=#select<br />postgres[2]-# *<br />postgres[3]-# from<br />postgres[4]-# abc;<br />ERROR:  relation "abc"
doesnot exist<br />LINE 4: abc;<br />        ^<br /><br />Now I used \e to edit the source. Deleted last line i.e.
"abc;"and<br /> returned to prompt, landed at line 4, typed "abc;"<br /><br />postgres[1]=# \e<br />postgres[4]-#
abc;<br/>ERROR:  relation "abc" does not exist<br />LINE 5: abc;<br />        ^<br /><br />In above steps, error
messagesays "LINE 5", where as on prompt "abc" is at<br /> line 4.<br /><br />postgres[1]=# select<br />*<br />from<br
/>abc;<br/>ERROR:  relation "abc" does not exist<br />LINE 4: abc;<br />        ^<br /><br />Here I again see error at
line4. Something fishy. Please investigate.<br />Looks like bug in LINE numbering in error message, not sure though.<br
/>But with prompt line number feature, it should be sync to each other.<br /><br /><br />B:<br />However, I see that
youhave removed the code changes related to INT_MAX.<br />Why?<br />I have set cur_line to INT_MAX - 2 and then
observedthat after 2 lines I<br /> start getting negative numbers.<br /><br />Thanks<br /></div><div
class="gmail_extra"><br/><br /><div class="gmail_quote">On Sun, Jul 6, 2014 at 10:48 PM, Sawada Masahiko <span
dir="ltr"><<ahref="mailto:sawada.mshk@gmail.com" target="_blank">sawada.mshk@gmail.com</a>></span> wrote:<br
/><blockquoteclass="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div
class="HOEnZb"><divclass="h5">On Fri, Jun 20, 2014 at 7:17 PM, Jeevan Chalke<br /> <<a
href="mailto:jeevan.chalke@enterprisedb.com">jeevan.chalke@enterprisedb.com</a>>wrote:<br /> > Hi Sawada
Masahiko,<br/> ><br /> > I liked this feature. So I have reviewed it.<br /> ><br /> > Changes are straight
forwardand looks perfect.<br /> > No issues found with make/make install/initdb/regression.<br /> ><br /> >
HoweverI would suggest removing un-necessary braces at if, as we have only<br /> > one statement into it.<br />
><br/> >     if (++cur_line >= INT_MAX)<br /> >     {<br /> >         cur_line = 1;<br /> >     }<br
/>><br /> > Also following looks wrong:<br /> ><br /> > postgres[1]=# select<br /> > postgres[2]-# *<br
/>> postgres[3]-# from<br /> > postgres[4]-# tab;<br /> >  a<br /> > ---<br /> > (0 rows)<br /> ><br
/>> postgres[1]=# select<br /> > *<br /> > from<br /> > tab<br /> > postgres[2]-# where t > 10;<br />
>ERROR:  column "t" does not exist<br /> > LINE 5: where t > 10;<br /> >               ^<br /> ><br />
>Line number in ERROR is 5 which is correct.<br /> > But line number in psql prompt is wrong.<br /> ><br />
>To get first 4 lines I have simply used up arrow followed by an enter for<br /> > which I was expecting 5 in
psqlprompt.<br /> > But NO it was 2 which is certainly wrong.<br /> ><br /> > Need to handle above
carefully.<br/> ><br /> > Thanks<br /> ><br /> ><br /> > On Thu, Jun 12, 2014 at 10:46 PM, Sawada
Masahiko<<a href="mailto:sawada.mshk@gmail.com">sawada.mshk@gmail.com</a>><br /> > wrote:<br /> >><br />
>>Hi all,<br /> >><br /> >> The attached IWP patch is one prompt option for psql, which shows<br />
>>current line number.<br /> >> If the user made syntax error with too long SQL then psql outputs<br />
>>message as following.<br /> >><br /> >> ERROR:  syntax error at or near "a"<br /> >> LINE
250:hoge<br /> >>                 ^<br /> >> psql teaches me where syntax error is occurred, but it is not
kind<br/> >> when SQL is too long.<br /> >> We can use write SQL with ¥e(editor) command(e.g., emacs) , and
wecan<br /> >> know line number.<br /> >> but it would make terminal log dirty . It will make analyzing of
log<br/> >> difficult after error is occurred.<br /> >> (I think that we usually use copy & paste)<br
/>>><br /> >> After attached this patch, we will be able to use %l option as prompting<br /> >>
option.<br/> >><br /> >> e.g.,<br /> >> $ cat ~/.psqlrc<br /> >> \set PROMPT2 '%/[%l]%R%# '<br
/>>> \set PROMPT1 '%/[%l]%R%# '<br /> >> $ psql -d postgres<br /> >> postgres[1]=# select<br />
>>postgres[2]-# *<br /> >> postgres[3]-# from<br /> >> postgres[4]-# hoge;<br /> >><br />
>>The past discussion is following.<br /> >><br /> >> <<a
href="http://www.postgresql.org/message-id/CAFj8pRC1ruPk6+chA1jpxPh3uS_zipaBDOvmcEex4wPbp2kZMQ@mail.gmail.com"
target="_blank">http://www.postgresql.org/message-id/CAFj8pRC1ruPk6+chA1jpxPh3uS_zipaBDOvmcEex4wPbp2kZMQ@mail.gmail.com</a>><br
/>>><br /> >> Please give me feedback.<br /> >><br /> >> Regards,<br /> >><br /> >>
-------<br/> >> Sawada Masahiko<br /> >><br /> >><br /> >> --<br /> >> Sent via
pgsql-hackersmailing list (<a href="mailto:pgsql-hackers@postgresql.org">pgsql-hackers@postgresql.org</a>)<br />
>>To make changes to your subscription:<br /> >> <a href="http://www.postgresql.org/mailpref/pgsql-hackers"
target="_blank">http://www.postgresql.org/mailpref/pgsql-hackers</a><br/> >><br /> ><br /> ><br /> ><br
/>> --<br /> > Jeevan B Chalke<br /> > Principal Software Engineer, Product Development<br /> >
EnterpriseDBCorporation<br /> > The Enterprise PostgreSQL Company<br /> ><br /> > Phone: +91 20 30589500<br />
><br/> > Website: <a href="http://www.enterprisedb.com" target="_blank">www.enterprisedb.com</a><br /> >
EnterpriseDBBlog: <a href="http://blogs.enterprisedb.com/" target="_blank">http://blogs.enterprisedb.com/</a><br />
>Follow us on Twitter: <a href="http://www.twitter.com/enterprisedb"
target="_blank">http://www.twitter.com/enterprisedb</a><br/> ><br /> > This e-mail message (and any attachment)
isintended for the use of the<br /> > individual or entity to whom it is addressed. This message contains<br /> >
informationfrom EnterpriseDB Corporation that may be privileged,<br /> > confidential, or exempt from disclosure
underapplicable law. If you are not<br /> > the intended recipient or authorized to receive this for the intended<br
/>> recipient, any use, dissemination, distribution, retention, archiving, or<br /> > copying of this
communicationis strictly prohibited. If you have received<br /> > this e-mail in error, please notify the sender
immediatelyby reply e-mail<br /> > and delete this message.<br /><br /></div></div>Thank you for reviewing patch,
andsorry for late response.<br /><br /> I have updated this patch, and attached it.<br /><div class=""><br /> >
postgres[1]=#select<br /> > *<br /> > from<br /> > tab<br /> > postgres[2]-# where t > 10;<br /> >
ERROR: column "t" does not exist<br /> > LINE 5: where t > 10;<br /></div>Attached patch can handle this case.<br
/><divclass="HOEnZb"><div class="h5"><br /> Please give me feedback.<br /><br /> Regards,<br /><br /> -------<br />
SawadaMasahiko<br /></div></div></blockquote></div><br /><br clear="all" /><br />-- <br /><div dir="ltr">Jeevan B
Chalke<br/>Principal Software Engineer, Product Development<br />EnterpriseDB Corporation<br />The Enterprise
PostgreSQLCompany<br /><br />Phone: +91 20 30589500<br /><br />Website: <a href="http://www.enterprisedb.com"
target="_blank">www.enterprisedb.com</a><br/>EnterpriseDB Blog: <a href="http://blogs.enterprisedb.com/"
target="_blank">http://blogs.enterprisedb.com/</a><br/>Follow us on Twitter: <a
href="http://www.twitter.com/enterprisedb"target="_blank">http://www.twitter.com/enterprisedb</a><br /><br />This
e-mailmessage (and any attachment) is intended for the use of the individual or entity to whom it is addressed. This
messagecontains information from EnterpriseDB Corporation that may be privileged, confidential, or exempt from
disclosureunder applicable law. If you are not the intended recipient or authorized to receive this for the intended
recipient,any use, dissemination, distribution, retention, archiving, or copying of this communication is strictly
prohibited.If you have received this e-mail in error, please notify the sender immediately by reply e-mail and delete
thismessage.</div></div> 

pgsql-hackers by date:

Previous
From: Rahila Syed
Date:
Subject: Re: [REVIEW] Re: Compression of full-page-writes
Next
From: Asif Naeem
Date:
Subject: Re: [bug fix or improvement?] Correctly place DLLs for ECPG apps in bin folder