Re: psql shows line number

Lists: pgsql-hackers
From: Sawada Masahiko <sawada(dot)mshk(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: psql shows line number
Date: 2013-11-26 12:05:24
Message-ID: CAD21AoBpuFLf4yazeckDcyDbxwb0DGMNnezGEtjMMnDqvnEoSA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi all,

When I execute query which contains error, the server returns error
with line number.

ERROR: relation "hoge" does not exist
LINE 35: hoge;

But when query is long, I was not sure the location where I wrote wrong SQL.
Does the psql have option which shows line number?
If no, I'm thinking to implement this feature. Thought?
I think it is useful if the psql shows line number like follows

[1]postgres=# SELECT
[2]postgres=# hoge.col1
[3]postgres=# FROM
[4]postgres=# hoge;

ERROR: column "col1" does not exist
LINE 2: col1

And If there is discussion at past about this, please let me know.

Regards,

-------
Sawada Masahiko


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Sawada Masahiko <sawada(dot)mshk(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql shows line number
Date: 2013-11-26 12:17:11
Message-ID: CAFj8pRC1ruPk6+chA1jpxPh3uS_zipaBDOvmcEex4wPbp2kZMQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2013/11/26 Sawada Masahiko <sawada(dot)mshk(at)gmail(dot)com>

> Hi all,
>
> When I execute query which contains error, the server returns error
> with line number.
>
> ERROR: relation "hoge" does not exist
> LINE 35: hoge;
>
> But when query is long, I was not sure the location where I wrote wrong
> SQL.
> Does the psql have option which shows line number?
> If no, I'm thinking to implement this feature. Thought?
> I think it is useful if the psql shows line number like follows
>
> [1]postgres=# SELECT
> [2]postgres=# hoge.col1
> [3]postgres=# FROM
> [4]postgres=# hoge;
>
> ERROR: column "col1" does not exist
> LINE 2: col1
>
> And If there is discussion at past about this, please let me know.
>

idea is interesting, but a proposed format is not clean (and little bit
ugly, and can be barrier for copy from terminal to editor. Now, simple
replace can be used for cleaning.

maybe we can introduce a command, that will print SQL from history with
line numbers - like \sf+

regards

Pavel

>
> Regards,
>
> -------
> Sawada Masahiko
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>


From: Marko Tiikkaja <marko(at)joh(dot)to>
To: Sawada Masahiko <sawada(dot)mshk(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql shows line number
Date: 2013-11-26 12:23:14
Message-ID: 529492B2.3080500@joh.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 11/26/13 1:05 PM, Sawada Masahiko wrote:
> When I execute query which contains error, the server returns error
> with line number.
>
> ERROR: relation "hoge" does not exist
> LINE 35: hoge;
>
> But when query is long, I was not sure the location where I wrote wrong SQL.
> Does the psql have option which shows line number?
> If no, I'm thinking to implement this feature. Thought?
> I think it is useful if the psql shows line number like follows

If the query is long, you'll likely want to \e to edit it anyway, no?
I'm sure any text editor worth $EDITOR will know how to jump to a
specific line.

Regards,
Marko Tiikkaja


From: Sawada Masahiko <sawada(dot)mshk(at)gmail(dot)com>
To: Marko Tiikkaja <marko(at)joh(dot)to>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql shows line number
Date: 2013-11-26 13:15:33
Message-ID: CAD21AoCKMZi++4cs5YrkRU2kFoy-ZhcSAkT9Pdxqsvd2QqMJ+Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Nov 26, 2013 at 9:23 PM, Marko Tiikkaja <marko(at)joh(dot)to> wrote:
> On 11/26/13 1:05 PM, Sawada Masahiko wrote:
>>
>> When I execute query which contains error, the server returns error
>> with line number.
>>
>> ERROR: relation "hoge" does not exist
>> LINE 35: hoge;
>>
>> But when query is long, I was not sure the location where I wrote wrong
>> SQL.
>> Does the psql have option which shows line number?
>> If no, I'm thinking to implement this feature. Thought?
>> I think it is useful if the psql shows line number like follows
>
>
> If the query is long, you'll likely want to \e to edit it anyway, no? I'm
> sure any text editor worth $EDITOR will know how to jump to a specific line.
Thanks!
¥e is also good. I didn't know this.
I thought that showing line number on psql is light and simple.
So I thought that psql can also have such feature as standard function.

> idea is interesting, but a proposed format is not clean (and little bit ugly, and
> can be barrier for copy from terminal to editor. Now, simple replace can be used for cleaning.
Thanks!
Yes, it is little ugly.
I was also thinking to fill space of line number with whitespace. likes:

[ 1]postgres=# SELECT
[ 2]postgres=# hoge.col1
:
[ 9]postgres=# FROM
[ 10]postgres=# hoge;

But I think that it is also something just isn't right.

> maybe we can introduce a command, that will print SQL from history with line numbers - like \sf+
I think that ¥sf+ shows definition of function. How should I use this?

Regards,

-------
Sawada Masahiko


From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Sawada Masahiko <sawada(dot)mshk(at)gmail(dot)com>
Cc: Marko Tiikkaja <marko(at)joh(dot)to>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql shows line number
Date: 2013-11-26 13:24:05
Message-ID: CAFj8pRD8_2tc4QRugHrGV1rouJOWLBsw3nRkm-y4HPd1kK9gJQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2013/11/26 Sawada Masahiko <sawada(dot)mshk(at)gmail(dot)com>

> On Tue, Nov 26, 2013 at 9:23 PM, Marko Tiikkaja <marko(at)joh(dot)to> wrote:
> > On 11/26/13 1:05 PM, Sawada Masahiko wrote:
> >>
> >> When I execute query which contains error, the server returns error
> >> with line number.
> >>
> >> ERROR: relation "hoge" does not exist
> >> LINE 35: hoge;
> >>
> >> But when query is long, I was not sure the location where I wrote wrong
> >> SQL.
> >> Does the psql have option which shows line number?
> >> If no, I'm thinking to implement this feature. Thought?
> >> I think it is useful if the psql shows line number like follows
> >
> >
> > If the query is long, you'll likely want to \e to edit it anyway, no?
> I'm
> > sure any text editor worth $EDITOR will know how to jump to a specific
> line.
> Thanks!
> ¥e is also good. I didn't know this.
> I thought that showing line number on psql is light and simple.
> So I thought that psql can also have such feature as standard function.
>
>
> > idea is interesting, but a proposed format is not clean (and little bit
> ugly, and
> > can be barrier for copy from terminal to editor. Now, simple replace
> can be used for cleaning.
> Thanks!
> Yes, it is little ugly.
> I was also thinking to fill space of line number with whitespace. likes:
>
> [ 1]postgres=# SELECT
> [ 2]postgres=# hoge.col1
> :
> [ 9]postgres=# FROM
> [ 10]postgres=# hoge;
>
> But I think that it is also something just isn't right.
>
> > maybe we can introduce a command, that will print SQL from history with
> line numbers - like \sf+
> I think that ¥sf+ shows definition of function. How should I use this?
>

yes, but we can define new statement like \sq+ (Show Query)

Pavel

>
> Regards,
>
> -------
> Sawada Masahiko
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>


From: Sawada Masahiko <sawada(dot)mshk(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Marko Tiikkaja <marko(at)joh(dot)to>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql shows line number
Date: 2013-11-26 13:42:04
Message-ID: CAD21AoCYFiepJh0iUUddW8PF6OMUm4be54vup7dLJecDMkqyEQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2013/11/26 22:24 "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>:
>
>
>
>
> 2013/11/26 Sawada Masahiko <sawada(dot)mshk(at)gmail(dot)com>
>>
>> On Tue, Nov 26, 2013 at 9:23 PM, Marko Tiikkaja <marko(at)joh(dot)to> wrote:
>> > On 11/26/13 1:05 PM, Sawada Masahiko wrote:
>> >>
>> >> When I execute query which contains error, the server returns error
>> >> with line number.
>> >>
>> >> ERROR: relation "hoge" does not exist
>> >> LINE 35: hoge;
>> >>
>> >> But when query is long, I was not sure the location where I wrote
wrong
>> >> SQL.
>> >> Does the psql have option which shows line number?
>> >> If no, I'm thinking to implement this feature. Thought?
>> >> I think it is useful if the psql shows line number like follows
>> >
>> >
>> > If the query is long, you'll likely want to \e to edit it anyway,
no? I'm
>> > sure any text editor worth $EDITOR will know how to jump to a specific
line.
>> Thanks!
>> ¥e is also good. I didn't know this.
>> I thought that showing line number on psql is light and simple.
>> So I thought that psql can also have such feature as standard function.
>>
>>
>> > idea is interesting, but a proposed format is not clean (and little
bit ugly, and
>> > can be barrier for copy from terminal to editor. Now, simple replace
can be used for cleaning.
>> Thanks!
>> Yes, it is little ugly.
>> I was also thinking to fill space of line number with whitespace. likes:
>>
>> [ 1]postgres=# SELECT
>> [ 2]postgres=# hoge.col1
>> :
>> [ 9]postgres=# FROM
>> [ 10]postgres=# hoge;
>>
>> But I think that it is also something just isn't right.
>>
>> > maybe we can introduce a command, that will print SQL from history
with line numbers - like \sf+
>> I think that ¥sf+ shows definition of function. How should I use this?
>
>
> yes, but we can define new statement like \sq+ (Show Query)
>
I understood.
it looks good to me.

it is similer to searching history(i.g., just push up-arrow-key)?

Regards,

Masahiko Sawada


From: Marko Tiikkaja <marko(at)joh(dot)to>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Sawada Masahiko <sawada(dot)mshk(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql shows line number
Date: 2013-11-26 13:43:14
Message-ID: 5294A572.1000303@joh.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 11/26/13 2:24 PM, Pavel Stehule wrote:
> yes, but we can define new statement like \sq+ (Show Query)

There's already \p; might not be too difficult to add a \p+ which would
also show the line numbers.

Regards,
Marko Tiikkaja


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Marko Tiikkaja <marko(at)joh(dot)to>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Sawada Masahiko <sawada(dot)mshk(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql shows line number
Date: 2013-11-26 15:22:50
Message-ID: 7078.1385479370@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Marko Tiikkaja <marko(at)joh(dot)to> writes:
> On 11/26/13 2:24 PM, Pavel Stehule wrote:
>> yes, but we can define new statement like \sq+ (Show Query)

> There's already \p; might not be too difficult to add a \p+ which would
> also show the line numbers.

I don't actually see the point of this. If you're working with queries
that are long enough that counting lines is even slightly difficult,
surely you're going to use \e to correct the problem? So it seems to
me that the existing "\e nnn" facility pretty much does what's needed,
and there's no great need to clutter your regular display with line
numbers.

regards, tom lane


From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Marko Tiikkaja <marko(at)joh(dot)to>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Sawada Masahiko <sawada(dot)mshk(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql shows line number
Date: 2013-11-26 15:37:14
Message-ID: CAHyXU0z53KivOSqmMozE=hz1grBCyAM9Pq1j+cEeFTcHJnXn2w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Nov 26, 2013 at 9:22 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Marko Tiikkaja <marko(at)joh(dot)to> writes:
>> On 11/26/13 2:24 PM, Pavel Stehule wrote:
>>> yes, but we can define new statement like \sq+ (Show Query)
>
>> There's already \p; might not be too difficult to add a \p+ which would
>> also show the line numbers.
>
> I don't actually see the point of this. If you're working with queries
> that are long enough that counting lines is even slightly difficult,
> surely you're going to use \e to correct the problem? So it seems to
> me that the existing "\e nnn" facility pretty much does what's needed,
> and there's no great need to clutter your regular display with line
> numbers.

I agree in the sense line numbers don't help. But \e is not really a
solution to the problem. A pretty common thing for me to see (as an
artifact of my styling) in the log:

ERROR: syntax error at or near "from"
LINE 223: from
^

Not very helpful. Also good luck if your SQL is dynamically
generated. What I think would help *would* be able to optionally add
a some lines of context: then you'd at least have a shot at eyeballing
the error etc.

merlin