This is a discussion on psql: recall previous command? within the pgsql Hackers forums, part of the PostgreSQL category; --> Is there a way to recall the previous command in psql? Obviously, "up arrow" or Ctrl-P using readline and ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| |||
| 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 ----------------------------------------------------------- ---------------------------(end of broadcast)--------------------------- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) |
| |||
| 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" ---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9' the postmaster |
| |||
| 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 ---------------------------(end of broadcast)--------------------------- TIP 8: explain analyze is your friend |
| |||
| 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 ---------------------------(end of broadcast)--------------------------- TIP 6: Have you searched our list archives? http://archives.postgresql.org |
| |||
| 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 ---------------------------(end of broadcast)--------------------------- TIP 7: don't forget to increase your free space map settings |
| |||
| 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, Pennsylvania 19073 ---------------------------(end of broadcast)--------------------------- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) |
| |||
| 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 ---------------------------(end of broadcast)--------------------------- TIP 8: explain analyze is your friend |
| |||
| 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 ---------------------------(end of broadcast)--------------------------- TIP 4: Don't 'kill -9' the postmaster |
| ||||
| 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, Pennsylvania 19073 ---------------------------(end of broadcast)--------------------------- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq |