psql slash# command

Lists: pgsql-hackerspgsql-patches
From: "Sibte Abbas" <sibtay(at)gmail(dot)com>
To: pgsql-patches(at)postgresql(dot)org
Subject: psql slash# command
Date: 2007-09-09 15:35:19
Message-ID: bd6a35510709090835t538c81bt368f98d42a69ad98@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Attached is the patch for the TODO item mentioned at
http://archives.postgresql.org/pgsql-hackers/2007-09/msg00352.php

The command has the following synopsis:

\#: displays the command history. Like \s but prefixes the lines with line
numbers

\# <line_no>: executes the command(if any) executed at the line specified by
line_no

regards,
--
Sibte Abbas

Attachment Content-Type Size
psql_slash#.patch text/x-patch 9.4 KB

From: "Sibte Abbas" <sibtay(at)gmail(dot)com>
To: pgsql-patches(at)postgresql(dot)org
Subject: Re: psql slash# command
Date: 2007-09-14 14:13:03
Message-ID: bd6a35510709140713t5f6bc5d8if4055b2efc999af6@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On 9/9/07, Sibte Abbas <sibtay(at)gmail(dot)com> wrote:
> Attached is the patch for the TODO item mentioned at
> http://archives.postgresql.org/pgsql-hackers/2007-09/msg00352.php
>
> The command has the following synopsis:
>
> \#: displays the command history. Like \s but prefixes the lines with line
> numbers
>
> \# <line_no>: executes the command(if any) executed at the line specified by
> line_no
>
> regards,
> --
> Sibte Abbas
>
>

The attached patch adds the following new functionality:

\#e <lineno>: Will open the command at the given lineno in an editor.
\#e with no lineno will behave exactly like \e.

Example:
=====

psql> \#

199: create or replace function foo() returns integer as $$
begin
return 10;
end;
$$language 'plpgsql';

200: select version();

201: select * from foo();

\# 200
<select version() is executed>

psql> \#e 199
<the contents of lineno 199 are opened in the editor>

Definitely not for 8.3, however I hope that it can be queued for 8.4.

thanks,
--
Sibte Abbas

Attachment Content-Type Size
psql_slash#_v2.patch text/x-patch 8.6 KB

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Sibte Abbas <sibtay(at)gmail(dot)com>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: psql slash# command
Date: 2007-09-14 14:17:01
Message-ID: 200709141417.l8EEH1b27953@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


This has been saved for the 8.4 release:

http://momjian.postgresql.org/cgi-bin/pgpatches_hold

---------------------------------------------------------------------------

Sibte Abbas wrote:
> On 9/9/07, Sibte Abbas <sibtay(at)gmail(dot)com> wrote:
> > Attached is the patch for the TODO item mentioned at
> > http://archives.postgresql.org/pgsql-hackers/2007-09/msg00352.php
> >
> > The command has the following synopsis:
> >
> > \#: displays the command history. Like \s but prefixes the lines with line
> > numbers
> >
> > \# <line_no>: executes the command(if any) executed at the line specified by
> > line_no
> >
> > regards,
> > --
> > Sibte Abbas
> >
> >
>
> The attached patch adds the following new functionality:
>
> \#e <lineno>: Will open the command at the given lineno in an editor.
> \#e with no lineno will behave exactly like \e.
>
> Example:
> =====
>
> psql> \#
>
> 199: create or replace function foo() returns integer as $$
> begin
> return 10;
> end;
> $$language 'plpgsql';
>
> 200: select version();
>
> 201: select * from foo();
>
> \# 200
> <select version() is executed>
>
> psql> \#e 199
> <the contents of lineno 199 are opened in the editor>
>
> Definitely not for 8.3, however I hope that it can be queued for 8.4.
>
> thanks,
> --
> Sibte Abbas

[ Attachment, skipping... ]

>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
> http://archives.postgresql.org

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Sibte Abbas" <sibtay(at)gmail(dot)com>
Cc: pgsql-patches(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCHES] psql slash# command
Date: 2008-03-30 19:09:20
Message-ID: 27011.1206904160@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

"Sibte Abbas" <sibtay(at)gmail(dot)com> writes:
> On 9/9/07, Sibte Abbas <sibtay(at)gmail(dot)com> wrote:
>> Attached is the patch for the TODO item mentioned at
>> http://archives.postgresql.org/pgsql-hackers/2007-09/msg00352.php

I looked this over and realized that it has little to do with the
functionality that was so painfully hashed out in the original
discussion thread here:

http://archives.postgresql.org/pgsql-hackers/2006-12/msg00207.php

As I understood it, the consensus was:

1. Invent a switch (probably a variable instead of a dedicated \-command)
that determines whether \s includes command numbers in its output.

2. Add "\# n" to re-execute command number n.

You've twisted this around into

>> \#: displays the command history. Like \s but prefixes the lines with line
>> numbers
>>
>> \# <line_no>: executes the command(if any) executed at the line specified by
>> line_no

This is a serious regression in functionality from what was agreed to,
because there is no possibility of shoehorning the equivalent of "\s file"
into it --- you've already decided that any argument is a line number.

It also seems to me to be pretty unintuitive and even dangerous that the
same \-command would do *fundamentally* different things depending on
whether it has an argument or not. Especially if one of those things
involves executing an arbitrary SQL-command.

> The attached patch adds the following new functionality:
> \#e <lineno>: Will open the command at the given lineno in an editor.
> \#e with no lineno will behave exactly like \e.

None of that was anywhere in the original discussion; and what pray
tell is the use of the second variant?

I wonder whether it wouldn't be safer and more convenient if we defined
'\# n' as pulling command n into the edit buffer, rather than
immediately executing it. Actual execution is only a <return> away,
but this definition would allow you to edit the command a bit more
before you execute it --- including \e to use an editor. It also
closes the loop in terms of providing some confidence that you typed
the number you should have typed.

BTW, not related to the original discussion, but I fail to understand
how anyone finds \s useful interactively, when it doesn't paginate
its output. Shouldn't we fix that?

regards, tom lane


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Sibte Abbas <sibtay(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: [PATCHES] psql slash# command
Date: 2008-04-03 00:33:16
Message-ID: 200804030033.m330XG711911@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


Based on recent patch feedback from Tom, this has been saved for the
next commit-fest:

http://momjian.postgresql.org/cgi-bin/pgpatches_hold

---------------------------------------------------------------------------

Tom Lane wrote:
> "Sibte Abbas" <sibtay(at)gmail(dot)com> writes:
> > On 9/9/07, Sibte Abbas <sibtay(at)gmail(dot)com> wrote:
> >> Attached is the patch for the TODO item mentioned at
> >> http://archives.postgresql.org/pgsql-hackers/2007-09/msg00352.php
>
> I looked this over and realized that it has little to do with the
> functionality that was so painfully hashed out in the original
> discussion thread here:
>
> http://archives.postgresql.org/pgsql-hackers/2006-12/msg00207.php
>
> As I understood it, the consensus was:
>
> 1. Invent a switch (probably a variable instead of a dedicated \-command)
> that determines whether \s includes command numbers in its output.
>
> 2. Add "\# n" to re-execute command number n.
>
> You've twisted this around into
>
> >> \#: displays the command history. Like \s but prefixes the lines with line
> >> numbers
> >>
> >> \# <line_no>: executes the command(if any) executed at the line specified by
> >> line_no
>
> This is a serious regression in functionality from what was agreed to,
> because there is no possibility of shoehorning the equivalent of "\s file"
> into it --- you've already decided that any argument is a line number.
>
> It also seems to me to be pretty unintuitive and even dangerous that the
> same \-command would do *fundamentally* different things depending on
> whether it has an argument or not. Especially if one of those things
> involves executing an arbitrary SQL-command.
>
> > The attached patch adds the following new functionality:
> > \#e <lineno>: Will open the command at the given lineno in an editor.
> > \#e with no lineno will behave exactly like \e.
>
> None of that was anywhere in the original discussion; and what pray
> tell is the use of the second variant?
>
> I wonder whether it wouldn't be safer and more convenient if we defined
> '\# n' as pulling command n into the edit buffer, rather than
> immediately executing it. Actual execution is only a <return> away,
> but this definition would allow you to edit the command a bit more
> before you execute it --- including \e to use an editor. It also
> closes the loop in terms of providing some confidence that you typed
> the number you should have typed.
>
> BTW, not related to the original discussion, but I fail to understand
> how anyone finds \s useful interactively, when it doesn't paginate
> its output. Shouldn't we fix that?
>
> regards, tom lane
>
> --
> 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

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: "Sibte Abbas" <sibtay(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-patches(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: psql slash# command
Date: 2008-04-03 23:54:23
Message-ID: bd6a35510804031654m5336b47bh3ab876d123defd26@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Sun, Mar 30, 2008 at 3:09 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

>
> I looked this over and realized that it has little to do with the
> functionality that was so painfully hashed out in the original
> discussion thread here:
>
> http://archives.postgresql.org/pgsql-hackers/2006-12/msg00207.php
>
> As I understood it, the consensus was:
>
> 1. Invent a switch (probably a variable instead of a dedicated \-command)
> that determines whether \s includes command numbers in its output.
>
> 2. Add "\# n" to re-execute command number n.
>
> You've twisted this around into
>
> >> \#: displays the command history. Like \s but prefixes the lines with
> line
> >> numbers
> >>
> >> \# <line_no>: executes the command(if any) executed at the line
> specified by
> >> line_no
>

This patch implements the specification described here:

http://archives.postgresql.org/pgsql-hackers/2006-12/msg00255.php

>
>
> This is a serious regression in functionality from what was agreed to,
> because there is no possibility of shoehorning the equivalent of "\s file"
> into it --- you've already decided that any argument is a line number.

It made sense to assume anything following a \# to be a number, since "#"
here denotes a number. However in order to prevent from bad input, there is
a check in the get_hist_entry() function.

> > The attached patch adds the following new functionality:
> > \#e <lineno>: Will open the command at the given lineno in an editor.
> > \#e with no lineno will behave exactly like \e.
>
> None of that was anywhere in the original discussion; and what pray
> tell is the use of the second variant?

The above mentioned link contains definitions for both of these. Also the
second variant here is just for completeness sake.

> I wonder whether it wouldn't be safer and more convenient if we defined
> '\# n' as pulling command n into the edit buffer, rather than
> immediately executing it. Actual execution is only a <return> away,
> but this definition would allow you to edit the command a bit more
> before you execute it --- including \e to use an editor. It also
> closes the loop in terms of providing some confidence that you typed
> the number you should have typed.
>

This makes more sense and also appears to be much safer. I will start
modifying the patch as per this approach now.

regards,
-- Sibte Abbas


From: "Sibte Abbas" <sibtay(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: psql slash# command
Date: 2008-04-11 00:56:46
Message-ID: bd6a35510804101756t2023f3b3x8d0b78b536a6ba6e@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

On Thu, Apr 3, 2008 at 7:54 PM, Sibte Abbas <sibtay(at)gmail(dot)com> wrote:

> On Sun, Mar 30, 2008 at 3:09 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:<http://archives.postgresql.org/pgsql-hackers/2006-12/msg00255.php>
>
>
> > I wonder whether it wouldn't be safer and more convenient if we defined
> > '\# n' as pulling command n into the edit buffer, rather than
> > immediately executing it. Actual execution is only a <return> away,
> > but this definition would allow you to edit the command a bit more
> > before you execute it --- including \e to use an editor. It also
> > closes the loop in terms of providing some confidence that you typed
> > the number you should have typed.
> >
>
> This makes more sense and also appears to be much safer. I will start
> modifying the patch as per this approach now.
>
>
Based on your feedback I have modified the attached patch as follows:

1) \# n opens command n into the edit buffer.

2) A new psql variable; SHOW_LINE_NO is added, which is consulted by the \s
command.
If it is set, \s prefixs each line of its output with an incrementing
line number.

regards,
-- Sibte Abbas

Attachment Content-Type Size
psql_slash#_v3.patch text/x-patch 16.7 KB