Re: Confusing behavior of psql's \e

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Chapman Flack <chap(at)anastigmatix(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Confusing behavior of psql's \e
Date: 2020-12-16 09:45:44
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: 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.

Laurenz Albe

Attachment Content-Type Size
0001-Improve-e-ef-and-ev-if-the-editor-is-quit.patch text/x-patch 6.0 KB

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2020-12-16 09:56:31 Re: Rethinking plpgsql's assignment implementation
Previous Message Amit Kapila 2020-12-16 09:24:02 Re: [HACKERS] logical decoding of two-phase transactions