Re: Confusing behavior of psql's \e - Mailing list pgsql-hackers

From Laurenz Albe
Subject Re: Confusing behavior of psql's \e
Date
Msg-id 5176a665d68a096ee5bce5b4e11823f791e5f72f.camel@cybertec.at
Whole thread Raw
In response to Re: Confusing behavior of psql's \e  (Chapman Flack <chap@anastigmatix.net>)
List pgsql-hackers
On Tue, 2020-12-01 at 11:34 -0500, Chapman Flack wrote:
> On 12/01/20 11:21, Laurenz Albe wrote:
> > On Tue, 2020-12-01 at 11:03 -0500, Chapman Flack wrote:
> > > > I propose to clear the query buffer if the
> > > > editor exits without modifying the file.
> > > 
> > > Or how about keeping the query buffer content unchanged, but not
> > > executing it? Then it's still there if you have another idea about
> > > editing it. It's easy enough to \r if you really want it gone.
> > 
> > What if the buffer was empty?  Would you want to get the previous
> > query in the query buffer?  I'd assume not...
> 
> I took your proposal to be specifically about what happens if the editor
> is exited with no change to the buffer, and in that case, I would suggest
> making no change to the buffer, but not re-executing it.
> 
> If the editor is exited after deliberately emptying the editor buffer,
> I would expect that to be treated as emptying the query buffer.
> 
> I don't foresee any case that would entail bringing a /previous/ query
> back into the query buffer.

I see I'll have to try harder.

The attached patch changes the behavior as follows:

- If the current query buffer is edited, and you quit the editor,
  the query buffer is retained.  This is as it used to be.

- If the query buffer is empty and you run \e, the previous query
  is edited (as it used to be), but quitting the editor will empty
  the query buffer and execute nothing.

- Similarly, if you "\e file" and quit the editor, nothing will
  be executed and the query buffer is emptied.

- The same behavior change applies to \ef and \ev.
  There is no need to retain the definition in the query buffer,
  you can always run the \ev or \ev again.

I consider this a bug fix, but one that shouldn't be backpatched.
Re-executing the previous query if the editor is quit is
annoying at least and dangerous at worst.

I'll add this patch to the next commitfest.

Yours,
Laurenz Albe

Attachment

pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: [HACKERS] logical decoding of two-phase transactions
Next
From: Pavel Stehule
Date:
Subject: Re: Rethinking plpgsql's assignment implementation