Re: psql: recall previous command?

Lists: pgsql-hackers
From: lsunley(at)mb(dot)sympatico(dot)ca
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql: recall previous command?
Date: 2005-02-22 03:41:58
Message-ID: 0ICA0011BQGMHZ@l-daemon
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

In <421AB48C(dot)4010604(at)samurai(dot)com>, on 02/22/05
at 03:26 PM, Neil Conway <neilc(at)samurai(dot)com> said:

>Is there a way to recall the previous command in psql? Obviously, "up
>arrow" or Ctrl-P using readline and the default readline bindings is
>close, but it recalls the previous _line_ of input. That is not at all
>the same thing in the case of a multiple line command, for example.

>If there is no way at present, I think there should be. Using "up arrow"
>is quite annoying when dealing with multiple line SQL statements.

>Two issues:

>- how to handle slash commands? Slash commands and SQL statements can be
>intermixed:

>neilc=# select 1 \timing
>Timing is off.
>neilc-# ;
> ?column?
>----------
> 1
>(1 row)

>So I'm not quite sure what the right behavior here is. We could always
>just ignore slash commands (the command would "recall the previous SQL
>statement") -- since few slash commands are multi-line, I don't think
>that would be too bad.

>- when a multiple-line command is recalled, how should it be presented
>in the psql input buffer? Perhaps we could strip newlines from recalled
>command text, so that the recalled command would fit on a single line.
>That would mean the recalled command would look somewhat different than
>how the user typed it, although of course the semantics of the query
>should be the same. Any better ideas?

>-Neil

How about a multi-line buffer that picks up everything from the last \g or
; to the next \g or ;

That would pick up everything, That could then be pushed into the input
buffer except for the last line containing the ; or \g The last line would
have to pushed in when the user pressed the return key.

--
-----------------------------------------------------------
lsunley(at)mb(dot)sympatico(dot)ca
-----------------------------------------------------------


From: Neil Conway <neilc(at)samurai(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: psql: recall previous command?
Date: 2005-02-22 04:26:52
Message-ID: 421AB48C.4010604@samurai.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Is there a way to recall the previous command in psql? Obviously, "up
arrow" or Ctrl-P using readline and the default readline bindings is
close, but it recalls the previous _line_ of input. That is not at all
the same thing in the case of a multiple line command, for example.

If there is no way at present, I think there should be. Using "up arrow"
is quite annoying when dealing with multiple line SQL statements.

Two issues:

- how to handle slash commands? Slash commands and SQL statements can be
intermixed:

neilc=# select 1 \timing
Timing is off.
neilc-# ;
?column?
----------
1
(1 row)

So I'm not quite sure what the right behavior here is. We could always
just ignore slash commands (the command would "recall the previous SQL
statement") -- since few slash commands are multi-line, I don't think
that would be too bad.

- when a multiple-line command is recalled, how should it be presented
in the psql input buffer? Perhaps we could strip newlines from recalled
command text, so that the recalled command would fit on a single line.
That would mean the recalled command would look somewhat different than
how the user typed it, although of course the semantics of the query
should be the same. Any better ideas?

-Neil


From: Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql: recall previous command?
Date: 2005-02-22 04:48:22
Message-ID: 20050222044822.GC20393@dcc.uchile.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, Feb 22, 2005 at 03:26:52PM +1100, Neil Conway wrote:
> Is there a way to recall the previous command in psql? Obviously, "up
> arrow" or Ctrl-P using readline and the default readline bindings is
> close, but it recalls the previous _line_ of input. That is not at all
> the same thing in the case of a multiple line command, for example.

Something else to be considered about readline behavior: prepending a #
on M-# is useless. -- in that context would be much better, or /* if in
a multiline command.

(Just something I have had in my to-do list for a while ...)

--
Alvaro Herrera (<alvherre[(at)]dcc(dot)uchile(dot)cl>)
"La felicidad no es maƱana. La felicidad es ahora"


From: Ian Barwick <barwick(at)gmail(dot)com>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql: recall previous command?
Date: 2005-02-22 07:18:19
Message-ID: 1d581afe05022123188561d56@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Tue, 22 Feb 2005 15:26:52 +1100, Neil Conway <neilc(at)samurai(dot)com> wrote:
> Is there a way to recall the previous command in psql? Obviously, "up
> arrow" or Ctrl-P using readline and the default readline bindings is
> close, but it recalls the previous _line_ of input. That is not at all
> the same thing in the case of a multiple line command, for example.

Just checking: do you mean something like the \e and \p commands?

test=> SELECT \timing
Timing is off.
test-> 'Hello World';
?column?
-------------
Hello World
(1 row)

test=> \p
SELECT
'Hello World';
test=>

Ian Barwick


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql: recall previous command?
Date: 2005-02-22 07:51:45
Message-ID: 6687.1109058705@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Neil Conway <neilc(at)samurai(dot)com> writes:
> - when a multiple-line command is recalled, how should it be presented
> in the psql input buffer? Perhaps we could strip newlines from recalled
> command text, so that the recalled command would fit on a single line.

That fails on at least three cases: -- comments, newlines separating
parts of quoted literals (cf bizarre SQL spec requirement that adjacent
literals are merged only if separated by a newline), and newlines
embedded in quoted literals. You could possibly work around the first
two cases by doing nontrivial editing of the query string, but I see no
way around the last one.

regards, tom lane


From: Darcy Buskermolen <darcy(at)wavefire(dot)com>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql: recall previous command?
Date: 2005-02-22 16:57:30
Message-ID: 200502220857.30131.darcy@wavefire.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On February 21, 2005 08:26 pm, Neil Conway wrote:
> Is there a way to recall the previous command in psql? Obviously, "up
> arrow" or Ctrl-P using readline and the default readline bindings is
> close, but it recalls the previous _line_ of input. That is not at all
> the same thing in the case of a multiple line command, for example.

Currently I use \e to bring up the last command (multiline) in the editor,
from this point I can just save it to execute it.

>
> If there is no way at present, I think there should be. Using "up arrow"
> is quite annoying when dealing with multiple line SQL statements.
>
> Two issues:
>
> - how to handle slash commands? Slash commands and SQL statements can be
> intermixed:
>
> neilc=# select 1 \timing
> Timing is off.
> neilc-# ;
> ?column?
> ----------
> 1
> (1 row)
>
> So I'm not quite sure what the right behavior here is. We could always
> just ignore slash commands (the command would "recall the previous SQL
> statement") -- since few slash commands are multi-line, I don't think
> that would be too bad.
>
> - when a multiple-line command is recalled, how should it be presented
> in the psql input buffer? Perhaps we could strip newlines from recalled
> command text, so that the recalled command would fit on a single line.
> That would mean the recalled command would look somewhat different than
> how the user typed it, although of course the semantics of the query
> should be the same. Any better ideas?
>
> -Neil
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend

--
Darcy Buskermolen
Wavefire Technologies Corp.
ph: 250.717.0200
fx: 250.763.1759
http://www.wavefire.com


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql: recall previous command?
Date: 2005-02-24 05:12:37
Message-ID: 200502240512.j1O5CbV24281@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Is there a TODO here?

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

Neil Conway wrote:
> Is there a way to recall the previous command in psql? Obviously, "up
> arrow" or Ctrl-P using readline and the default readline bindings is
> close, but it recalls the previous _line_ of input. That is not at all
> the same thing in the case of a multiple line command, for example.
>
> If there is no way at present, I think there should be. Using "up arrow"
> is quite annoying when dealing with multiple line SQL statements.
>
> Two issues:
>
> - how to handle slash commands? Slash commands and SQL statements can be
> intermixed:
>
> neilc=# select 1 \timing
> Timing is off.
> neilc-# ;
> ?column?
> ----------
> 1
> (1 row)
>
> So I'm not quite sure what the right behavior here is. We could always
> just ignore slash commands (the command would "recall the previous SQL
> statement") -- since few slash commands are multi-line, I don't think
> that would be too bad.
>
> - when a multiple-line command is recalled, how should it be presented
> in the psql input buffer? Perhaps we could strip newlines from recalled
> command text, so that the recalled command would fit on a single line.
> That would mean the recalled command would look somewhat different than
> how the user typed it, although of course the semantics of the query
> should be the same. Any better ideas?
>
> -Neil
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Thomas F(dot)O'Connell <tfo(at)sitening(dot)com>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql: recall previous command?
Date: 2005-02-24 21:01:05
Message-ID: e37264a0db39a20b3e1a069ec66765cb@sitening.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

One interesting artifact of using \e to edit a multi-line command is
that the same command is then treated as a single-line command in
subsequent up-arrow or Ctrl-P attempts.

I use this frequently to achieve a similar effect to what you're after.
The one downside is that if you leave the psql session, it's returned
to multi-line format in the psql history.

-tfo

--
Thomas F. O'Connell
Co-Founder, Information Architect
Sitening, LLC
http://www.sitening.com/
110 30th Avenue North, Suite 6
Nashville, TN 37203-6320
615-260-0005d

On Feb 21, 2005, at 10:26 PM, Neil Conway wrote:

> Is there a way to recall the previous command in psql? Obviously, "up
> arrow" or Ctrl-P using readline and the default readline bindings is
> close, but it recalls the previous _line_ of input. That is not at all
> the same thing in the case of a multiple line command, for example.
>
> If there is no way at present, I think there should be. Using "up
> arrow"
> is quite annoying when dealing with multiple line SQL statements.
>
> Two issues:
>
> - how to handle slash commands? Slash commands and SQL statements can
> be intermixed:
>
> neilc=# select 1 \timing
> Timing is off.
> neilc-# ;
> ?column?
> ----------
> 1
> (1 row)
>
> So I'm not quite sure what the right behavior here is. We could always
> just ignore slash commands (the command would "recall the previous SQL
> statement") -- since few slash commands are multi-line, I don't think
> that would be too bad.
>
> - when a multiple-line command is recalled, how should it be presented
> in the psql input buffer? Perhaps we could strip newlines from
> recalled command text, so that the recalled command would fit on a
> single line. That would mean the recalled command would look somewhat
> different than how the user typed it, although of course the semantics
> of the query should be the same. Any better ideas?
>
> -Neil
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 8: explain analyze is your friend


From: Neil Conway <neilc(at)samurai(dot)com>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql: recall previous command?
Date: 2005-02-24 23:03:28
Message-ID: 421E5D40.7080405@samurai.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian wrote:
> Is there a TODO here?

Probably -- I think there is definitely room for improving psql's
handling of multi-line queries. However, \e works well enough for me,
and I don't think I'll get around to looking at this for 8.1. So feel
free to add a TODO item.

-Neil


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql: recall previous command?
Date: 2005-02-24 23:56:55
Message-ID: 200502242356.j1ONutf29008@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Neil Conway wrote:
> Bruce Momjian wrote:
> > Is there a TODO here?
>
> Probably -- I think there is definitely room for improving psql's
> handling of multi-line queries. However, \e works well enough for me,
> and I don't think I'll get around to looking at this for 8.1. So feel
> free to add a TODO item.

And what would the TODO item be? "Improve psql's handling of multi-line
queries" is too vague.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Neil Conway <neilc(at)samurai(dot)com>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql: recall previous command?
Date: 2005-02-25 00:11:31
Message-ID: 421E6D33.5000308@samurai.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Bruce Momjian wrote:
> And what would the TODO item be? "Improve psql's handling of multi-line
> queries" is too vague.

If you can include a link to the archives or the text of the relevant
mails, it seems fine to me. I'm not sure specifically _how_ we want to
improve the handling of multi-line queries, and it seems silly to make
that decision now just for the sake of a specific TODO item description.

-Neil


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql: recall previous command?
Date: 2005-02-25 00:24:29
Message-ID: 200502250024.j1P0OTa03423@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Neil Conway wrote:
> Bruce Momjian wrote:
> > And what would the TODO item be? "Improve psql's handling of multi-line
> > queries" is too vague.
>
> If you can include a link to the archives or the text of the relevant
> mails, it seems fine to me. I'm not sure specifically _how_ we want to
> improve the handling of multi-line queries, and it seems silly to make
> that decision now just for the sake of a specific TODO item description.

OK, I will just add the wording.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073