Обсуждение: psql: recall previous command?

Поиск
Список
Период
Сортировка

psql: recall previous command?

От
Neil Conway
Дата:
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



Re: psql: recall previous command?

От
lsunley@mb.sympatico.ca
Дата:
In <421AB48C.4010604@samurai.com>, on 02/22/05   at 03:26 PM, Neil Conway <neilc@samurai.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@mb.sympatico.ca
-----------------------------------------------------------



Re: psql: recall previous command?

От
Alvaro Herrera
Дата:
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[@]dcc.uchile.cl>)
"La felicidad no es mañana. La felicidad es ahora"


Re: psql: recall previous command?

От
Ian Barwick
Дата:
On Tue, 22 Feb 2005 15:26:52 +1100, Neil Conway <neilc@samurai.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


Re: psql: recall previous command?

От
Tom Lane
Дата:
Neil Conway <neilc@samurai.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


Re: psql: recall previous command?

От
Darcy Buskermolen
Дата:
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


Re: psql: recall previous command?

От
Bruce Momjian
Дата:
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@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073
 


Re: psql: recall previous command?

От
Thomas F.O'Connell
Дата:
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



Re: psql: recall previous command?

От
Neil Conway
Дата:
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


Re: psql: recall previous command?

От
Bruce Momjian
Дата:
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@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073
 


Re: psql: recall previous command?

От
Neil Conway
Дата:
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


Re: psql: recall previous command?

От
Bruce Momjian
Дата:
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@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073