psql and readline

Started by Christopher Kings-Lynneover 23 years ago55 messageshackers
Jump to latest
#1Christopher Kings-Lynne
chriskl@familyhealth.com.au

Hi,

Is there any way of making the 'up' arrow retrieve all of the last multiline
query, instead of just the last line? It's really annoying working with
large multiline queries at the moment...

Chris

#2Ian Lawrence Barwick
barwick@gmail.com
In reply to: Christopher Kings-Lynne (#1)
Re: psql and readline

On Wednesday 08 January 2003 07:55, Christopher Kings-Lynne wrote:

Hi,

Is there any way of making the 'up' arrow retrieve all of the last
multiline query, instead of just the last line? It's really annoying
working with large multiline queries at the moment...

Not that I know of, but you can use \e to edit the query in your
favourite editor.

Ian Barwick
barwick@gmx.net

#3Alexander M. Pravking
fduch@antar.bryansk.ru
In reply to: Ian Lawrence Barwick (#2)
Re: psql and readline

On Wed, Jan 08, 2003 at 10:53:51AM +0100, Ian Barwick wrote:

On Wednesday 08 January 2003 07:55, Christopher Kings-Lynne wrote:

Hi,

Is there any way of making the 'up' arrow retrieve all of the last
multiline query, instead of just the last line? It's really annoying
working with large multiline queries at the moment...

Not that I know of, but you can use \e to edit the query in your
favourite editor.

Sure. But \e puts "\e" into history, instead of the query itself :(

--
Fduch M. Pravking

#4Ian Lawrence Barwick
barwick@gmail.com
In reply to: Alexander M. Pravking (#3)
Re: psql and readline

On Wednesday 08 January 2003 13:02, Alexander M. Pravking wrote:

On Wed, Jan 08, 2003 at 10:53:51AM +0100, Ian Barwick wrote:

On Wednesday 08 January 2003 07:55, Christopher Kings-Lynne wrote:

Hi,

Is there any way of making the 'up' arrow retrieve all of the last
multiline query, instead of just the last line? It's really annoying
working with large multiline queries at the moment...

Not that I know of, but you can use \e to edit the query in your
favourite editor.

Sure. But \e puts "\e" into history, instead of the query itself :(

Yes, but the query will remain in the psql query buffer until a different
SQL query (i.e. not a slash command) is executed. Until then
you can reedit and / or reexecute the query (with \g) as long as you like.

Ian Barwick
barwick@gmx.net

#5Gavin Sherry
swm@linuxworld.com.au
In reply to: Christopher Kings-Lynne (#1)
Re: psql and readline

On Wed, 8 Jan 2003, Christopher Kings-Lynne wrote:

Hi,

Is there any way of making the 'up' arrow retrieve all of the last multiline
query, instead of just the last line? It's really annoying working with
large multiline queries at the moment...

When you say multiline do you mean this:

template1=$ select * from
template1-$ abc a
template1-$ where a.id=1;

or a situation where the query text exceeds the terminal width and wraps
to the next line? If the latter, see if horizontal-scroll-mode is set to
off in your ~/.inputrc. If the former, that sounds kind of elaborate and
to wrong way to do things.

Chris

Gavin

#6Christopher Kings-Lynne
chriskl@familyhealth.com.au
In reply to: Gavin Sherry (#5)
Re: psql and readline

Is there any way of making the 'up' arrow retrieve all of the last multiline
query, instead of just the last line? It's really annoying working with
large multiline queries at the moment...

When you say multiline do you mean this:

template1=$ select * from
template1-$ abc a
template1-$ where a.id=1;

Yes. Basically, the classic example is when I copy and paste large
queries or DDL from my SQL files in CVS. It's a real pain.

Chris

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alexander M. Pravking (#3)
Re: psql and readline

"Alexander M. Pravking" <fduch@antar.bryansk.ru> writes:

On Wed, Jan 08, 2003 at 10:53:51AM +0100, Ian Barwick wrote:

On Wednesday 08 January 2003 07:55, Christopher Kings-Lynne wrote:

Is there any way of making the 'up' arrow retrieve all of the last
multiline query, instead of just the last line? It's really annoying
working with large multiline queries at the moment...

Not that I know of, but you can use \e to edit the query in your
favourite editor.

Sure. But \e puts "\e" into history, instead of the query itself :(

Hm, so it does. It seems like the edited query should go into history,
at least when you execute it. Peter, is this fixable?

regards, tom lane

#8Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#7)
Re: psql and readline

Tom Lane wrote:

"Alexander M. Pravking" <fduch@antar.bryansk.ru> writes:

On Wed, Jan 08, 2003 at 10:53:51AM +0100, Ian Barwick wrote:

On Wednesday 08 January 2003 07:55, Christopher Kings-Lynne wrote:

Is there any way of making the 'up' arrow retrieve all of the last
multiline query, instead of just the last line? It's really annoying
working with large multiline queries at the moment...

Not that I know of, but you can use \e to edit the query in your
favourite editor.

Sure. But \e puts "\e" into history, instead of the query itself :(

Hm, so it does. It seems like the edited query should go into history,
at least when you execute it. Peter, is this fixable?

Wow, that would be a nifty trick, though they really did type \e and not
the query the pulled in from the editor.

-- 
  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
#9Dan Langille
dan@langille.org
In reply to: Bruce Momjian (#8)
Re: psql and readline

On 8 Jan 2003 at 12:28, Bruce Momjian wrote:

Tom Lane wrote:

"Alexander M. Pravking" <fduch@antar.bryansk.ru> writes:

On Wed, Jan 08, 2003 at 10:53:51AM +0100, Ian Barwick wrote:

On Wednesday 08 January 2003 07:55, Christopher Kings-Lynne
wrote:

Is there any way of making the 'up' arrow retrieve all of the
last multiline query, instead of just the last line? It's
really annoying working with large multiline queries at the
moment...

Not that I know of, but you can use \e to edit the query in your
favourite editor.

Sure. But \e puts "\e" into history, instead of the query itself
:(

Hm, so it does. It seems like the edited query should go into
history, at least when you execute it. Peter, is this fixable?

Wow, that would be a nifty trick, though they really did type \e and
not the query the pulled in from the editor.

What about those of us who want to use \e repeatedly? Will that be
in the history buffer?
--
Dan Langille : http://www.langille.org/

#10Peter T Mount
peter@retep.org.uk
In reply to: Dan Langille (#9)
Re: psql and readline

On Wed, 8 Jan 2003, Dan Langille wrote:

On 8 Jan 2003 at 12:28, Bruce Momjian wrote:

Tom Lane wrote:

"Alexander M. Pravking" <fduch@antar.bryansk.ru> writes:

On Wed, Jan 08, 2003 at 10:53:51AM +0100, Ian Barwick wrote:

On Wednesday 08 January 2003 07:55, Christopher Kings-Lynne
wrote:

Is there any way of making the 'up' arrow retrieve all of the
last multiline query, instead of just the last line? It's
really annoying working with large multiline queries at the
moment...

Not that I know of, but you can use \e to edit the query in your
favourite editor.

Sure. But \e puts "\e" into history, instead of the query itself
:(

Hm, so it does. It seems like the edited query should go into
history, at least when you execute it. Peter, is this fixable?

Wow, that would be a nifty trick, though they really did type \e and
not the query the pulled in from the editor.

What about those of us who want to use \e repeatedly? Will that be
in the history buffer?

The number of times I've cursed things over the years, I would have
thought having the edited query in the history would be more useful than
\e - the latter is only three key presses any how ;-)

Peter

--
Peter Mount
peter@retep.org.uk
http://www.retep.org.uk/
Tel/Fax: +44 (0) 1622 749439
Mobile: +44 (0) 7903 155887
US Fax: 1 435 304 5165
US Voice: 1 435 304 5165

#11Robert Treat
xzilla@users.sourceforge.net
In reply to: Peter T Mount (#10)
Re: psql and readline

On Thu, 2003-01-09 at 08:45, Peter Mount wrote:

On Wed, 8 Jan 2003, Dan Langille wrote:

On 8 Jan 2003 at 12:28, Bruce Momjian wrote:

Tom Lane wrote:

"Alexander M. Pravking" <fduch@antar.bryansk.ru> writes:

On Wed, Jan 08, 2003 at 10:53:51AM +0100, Ian Barwick wrote:

On Wednesday 08 January 2003 07:55, Christopher Kings-Lynne
wrote:

Is there any way of making the 'up' arrow retrieve all of the
last multiline query, instead of just the last line? It's
really annoying working with large multiline queries at the
moment...

Not that I know of, but you can use \e to edit the query in your
favourite editor.

Sure. But \e puts "\e" into history, instead of the query itself
:(

Hm, so it does. It seems like the edited query should go into
history, at least when you execute it. Peter, is this fixable?

Wow, that would be a nifty trick, though they really did type \e and
not the query the pulled in from the editor.

What about those of us who want to use \e repeatedly? Will that be
in the history buffer?

The number of times I've cursed things over the years, I would have
thought having the edited query in the history would be more useful than
\e - the latter is only three key presses any how ;-)

Or if the query could be appended after the \e, it would only be a quick
"double-up" to get back to the \e.

Robert Treat

#12Dan Langille
dan@langille.org
In reply to: Robert Treat (#11)
Re: psql and readline

On 9 Jan 2003 at 9:15, Robert Treat wrote:

On Thu, 2003-01-09 at 08:45, Peter Mount wrote:

On Wed, 8 Jan 2003, Dan Langille wrote:

On 8 Jan 2003 at 12:28, Bruce Momjian wrote:

Tom Lane wrote:

"Alexander M. Pravking" <fduch@antar.bryansk.ru> writes:

On Wed, Jan 08, 2003 at 10:53:51AM +0100, Ian Barwick wrote:

On Wednesday 08 January 2003 07:55, Christopher Kings-Lynne
wrote:

Is there any way of making the 'up' arrow retrieve all of
the last multiline query, instead of just the last line?
It's really annoying working with large multiline queries
at the moment...

Not that I know of, but you can use \e to edit the query in
your favourite editor.

Sure. But \e puts "\e" into history, instead of the query
itself :(

Hm, so it does. It seems like the edited query should go into
history, at least when you execute it. Peter, is this
fixable?

Wow, that would be a nifty trick, though they really did type \e
and not the query the pulled in from the editor.

What about those of us who want to use \e repeatedly? Will that
be in the history buffer?

The number of times I've cursed things over the years, I would have
thought having the edited query in the history would be more useful
than \e - the latter is only three key presses any how ;-)

Or if the query could be appended after the \e, it would only be a
quick "double-up" to get back to the \e.

As this is changing existing behaviour, I think adding an optional
switch to revert to the old behaviour is a good idea.
--
Dan Langille : http://www.langille.org/

#13John Liu
johnl@synthesys.com
In reply to: Robert Treat (#11)
clock sync

How do I know the clock on the machine you're
running on will be set to the same time as the
clock on the database? how postgre handle this
internal?

thanks.

johnl

#14Justin Clift
justin@postgresql.org
In reply to: Dan Langille (#12)
Re: psql and readline

Dan Langille wrote:
<snip>

As this is changing existing behaviour, I think adding an optional
switch to revert to the old behaviour is a good idea.

Two thoughts:

a) Is it possible to change the behavior of the history as we're
discussing? Haven't heard Peter's response to this.

b) Do we really want to go to the effort of adding a switch to revert to
previous behaviour for something like this? It's almost definitely a
win to have \e commands appear in the history, and seems a bit to
trivial for adding switches for.

?

Regards and best wishes,

Justin Clift

--
"My grandfather once told me that there are two kinds of people: those
who work and those who take the credit. He told me to try to be in the
first group; there was less competition there."
- Indira Gandhi

#15Justin Clift
justin@postgresql.org
In reply to: Justin Clift (#14)
Re: psql and readline

Justin Clift wrote:

b) Do we really want to go to the effort of adding a switch to revert to
previous behaviour for something like this? It's almost definitely a
win to have \e commands appear in the history, and seems a bit to
trivial for adding switches for.

Bad wording there... "\e commands" is meant to mean "commands created
through using \e"

--
"My grandfather once told me that there are two kinds of people: those
who work and those who take the credit. He told me to try to be in the
first group; there was less competition there."
- Indira Gandhi

#16Dan Langille
dan@langille.org
In reply to: Peter T Mount (#10)
Re: psql and readline

resent with my real mail address...

On 9 Jan 2003 at 13:45, Peter Mount wrote:

On Wed, 8 Jan 2003, Dan Langille wrote:

On 8 Jan 2003 at 12:28, Bruce Momjian wrote:

Tom Lane wrote:

"Alexander M. Pravking" <fduch@antar.bryansk.ru> writes:

On Wed, Jan 08, 2003 at 10:53:51AM +0100, Ian Barwick wrote:

On Wednesday 08 January 2003 07:55, Christopher Kings-Lynne
wrote:

Is there any way of making the 'up' arrow retrieve all of the
last multiline query, instead of just the last line? It's really
annoying working with large multiline queries at the moment...

Not that I know of, but you can use \e to edit the query in your
favourite editor.

Sure. But \e puts "\e" into history, instead of the query itself :(

Hm, so it does. It seems like the edited query should go into
history, at least when you execute it. Peter, is this fixable?

Wow, that would be a nifty trick, though they really did type \e and
not the query the pulled in from the editor.

What about those of us who want to use \e repeatedly? Will that be in
the history buffer?

The number of times I've cursed things over the years, I would have
thought having the edited query in the history would be more useful than \e
- the latter is only three key presses any how ;-)

It is easier to edit things within an editor than within the command line,
especially if using very long complex statements involving 8 or 9 tables
and nested/outer JOINS.
--
Dan Langille : http://www.langille.org/

#17Bruce Momjian
bruce@momjian.us
In reply to: Justin Clift (#14)
Re: psql and readline

Justin Clift wrote:

Dan Langille wrote:
<snip>

As this is changing existing behaviour, I think adding an optional
switch to revert to the old behaviour is a good idea.

Two thoughts:

a) Is it possible to change the behavior of the history as we're
discussing? Haven't heard Peter's response to this.

b) Do we really want to go to the effort of adding a switch to revert to
previous behaviour for something like this? It's almost definitely a
win to have \e commands appear in the history, and seems a bit to
trivial for adding switches for.

Let's suppose I am writing a query, and then I do \e to edit the query,
and I exit the editor and return to psql. Suppose I decide I want to
reedit, so I up arrow. I would expect to get \e, not the query I just
edited, no?

-- 
  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
#18Justin Clift
justin@postgresql.org
In reply to: Bruce Momjian (#17)
Re: psql and readline

Bruce Momjian wrote:
<snip>

Let's suppose I am writing a query, and then I do \e to edit the query,
and I exit the editor and return to psql. Suppose I decide I want to
reedit, so I up arrow. I would expect to get \e, not the query I just
edited, no?

Wouldn't it depend on how this gets implemented?

Maybe least negative impact approach (suggested already): If the "large
command that was edited" is put in the command history before the \e,
then both are available and there is no big change from "expected
behaviour".

i.e. one up arrow get the previous \e, and a second up arrow would bring
up the command that was worked upon.

?

Regards and best wishes,

Justin Clift

--
"My grandfather once told me that there are two kinds of people: those
who work and those who take the credit. He told me to try to be in the
first group; there was less competition there."
- Indira Gandhi

#19Bruce Momjian
bruce@momjian.us
In reply to: Justin Clift (#18)
Re: psql and readline

Justin Clift wrote:

Bruce Momjian wrote:
<snip>

Let's suppose I am writing a query, and then I do \e to edit the query,
and I exit the editor and return to psql. Suppose I decide I want to
reedit, so I up arrow. I would expect to get \e, not the query I just
edited, no?

Wouldn't it depend on how this gets implemented?

Maybe least negative impact approach (suggested already): If the "large
command that was edited" is put in the command history before the \e,
then both are available and there is no big change from "expected
behaviour".

i.e. one up arrow get the previous \e, and a second up arrow would bring
up the command that was worked upon.

Makese sense. However, it still has the shock factor of displaying a
huge query, which is usually what is involved when using the editor. I
don't feel strongly either way --- I am just pointing out the issue.

-- 
  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
#20Peter T Mount
peter@retep.org.uk
In reply to: Justin Clift (#18)
Re: psql and readline

On Fri, 10 Jan 2003, Justin Clift wrote:

Bruce Momjian wrote:
<snip>

Let's suppose I am writing a query, and then I do \e to edit the query,
and I exit the editor and return to psql. Suppose I decide I want to
reedit, so I up arrow. I would expect to get \e, not the query I just
edited, no?

Wouldn't it depend on how this gets implemented?

Maybe least negative impact approach (suggested already): If the "large
command that was edited" is put in the command history before the \e,
then both are available and there is no big change from "expected
behaviour".

i.e. one up arrow get the previous \e, and a second up arrow would bring
up the command that was worked upon.

Yes, that would then not confuse things too much when someone expects \e
as that's the last thing they typed.

The main benefit I can see is when you have entered a large query, then a
smaller one (or another \ command), and want to re-run the large query.
Currently you could use the terminal's history and copy/paste it, but if
you edited the query with \e then that doesn't work (or worse if the
terminal doesn't support it, or it's scrolled off the top of the buffer).

Peter

--
Peter Mount
peter@retep.org.uk
http://www.retep.org.uk/
Tel/Fax: +44 (0) 1622 749439
Mobile: +44 (0) 7903 155887
US Fax: 1 435 304 5165
US Voice: 1 435 304 5165

#21Dan Langille
dan@langille.org
In reply to: Bruce Momjian (#19)
#22Rod Taylor
rbt@rbt.ca
In reply to: Justin Clift (#18)
#23Chris Browne
cbbrowne@acm.org
In reply to: Bruce Momjian (#19)
#24Peter T Mount
peter@retep.org.uk
In reply to: Rod Taylor (#22)
#25Chris Browne
cbbrowne@acm.org
In reply to: John Liu (#13)
#26Rod Taylor
rbt@rbt.ca
In reply to: Peter T Mount (#24)
#27Bruce Momjian
bruce@momjian.us
In reply to: Rod Taylor (#26)
#28Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#27)
#29Peter T Mount
peter@retep.org.uk
In reply to: Bruce Momjian (#27)
#30Justin Clift
justin@postgresql.org
In reply to: Tom Lane (#28)
#31Jean-Paul ARGUDO
jean-paul.argudo@wanadoo.fr
In reply to: Christopher Kings-Lynne (#6)
#32Tom Lane
tgl@sss.pgh.pa.us
In reply to: Jean-Paul ARGUDO (#31)
#33Peter Eisentraut
peter_e@gmx.net
In reply to: Christopher Kings-Lynne (#1)
#34Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#28)
#35Ross J. Reedstrom
reedstrm@rice.edu
In reply to: Peter Eisentraut (#33)
#36Peter T Mount
peter@retep.org.uk
In reply to: Peter Eisentraut (#34)
#37Ross J. Reedstrom
reedstrm@rice.edu
In reply to: Peter T Mount (#36)
#38Peter Eisentraut
peter_e@gmx.net
In reply to: Ross J. Reedstrom (#37)
#39Ross J. Reedstrom
reedstrm@rice.edu
In reply to: Peter Eisentraut (#38)
#40Eric Ridge
ebr@tcdi.com
In reply to: Ross J. Reedstrom (#37)
#41Peter Eisentraut
peter_e@gmx.net
In reply to: Eric Ridge (#40)
#42Bruce Momjian
bruce@momjian.us
In reply to: Ross J. Reedstrom (#39)
#43Bruce Momjian
bruce@momjian.us
In reply to: Ross J. Reedstrom (#39)
#44Patrick Welche
prlw1@newn.cam.ac.uk
In reply to: Bruce Momjian (#43)
#45Tom Lane
tgl@sss.pgh.pa.us
In reply to: Patrick Welche (#44)
#46Patrick Welche
prlw1@newn.cam.ac.uk
In reply to: Tom Lane (#45)
#47Tom Lane
tgl@sss.pgh.pa.us
In reply to: Patrick Welche (#46)
#48Ross J. Reedstrom
reedstrm@rice.edu
In reply to: Ross J. Reedstrom (#39)
#49Patrick Welche
prlw1@newn.cam.ac.uk
In reply to: Ross J. Reedstrom (#39)
#50Peter Eisentraut
peter_e@gmx.net
In reply to: Ross J. Reedstrom (#48)
#51Ross J. Reedstrom
reedstrm@rice.edu
In reply to: Peter Eisentraut (#50)
#52Peter Eisentraut
peter_e@gmx.net
In reply to: Ross J. Reedstrom (#51)
#53Ross J. Reedstrom
reedstrm@rice.edu
In reply to: Peter Eisentraut (#52)
#54Bruce Momjian
bruce@momjian.us
In reply to: Ross J. Reedstrom (#53)
#55Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#54)