Re: Confusing behavior of psql's \e

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Jacob Champion <pchampion(at)vmware(dot)com>
Cc: "chap(at)anastigmatix(dot)net" <chap(at)anastigmatix(dot)net>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Confusing behavior of psql's \e
Date: 2021-03-03 16:08:22
Message-ID: 76542d1466e9bfe3d442a9eeb7c70ac5620e55ef.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thanks for testing!

On Wed, 2021-03-03 at 00:07 +0000, Jacob Champion wrote:
> On Wed, 2020-12-16 at 10:45 +0100, Laurenz Albe wrote:
>
> > 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 like that this patch also clears the query buffer in the error case.
> (For example, if I save the file but then decide I want to cancel
> execution, the only choice is to issue an abortive :cq from Vim. The
> current master-branch behavior is to just dump me back onto a
> continuation prompt, and I have to manually \r the buffer. With this
> patch, I'm returned to an initial prompt with a clear buffer. Very
> nice.)
>
> Some unexpected behavior I saw when testing this patch: occasionally I
> would perform a bare \e, save the temporary file, and quit, only to
> find that nothing was executed. What's happening is, I'm saving the
> file too quickly, and the timestamp check (which has only second
> precision) is failing! This isn't a problem in practice for the
> explicit-filename case, because you probably didn't create the file
> within the last second, but the temporary files are always zero seconds
> old by definition. I could see this tripping up some people.

That is because psql compares the file modification time before and
after the edit, and the "st_mtime" in "struct stat" has a precision of
seconds. Some operating systems and file provide a finer granularity,
but for example PostgreSQL's _pgstat64 that is used on Windows doesn't.

This is no new behavior, and I think this is rare enough that we don't
have to bother. I had to define a vim macro to :wq the file fast
enough to reproduce your observation...

Yours,
Laurenz Albe

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Steele 2021-03-03 16:14:20 Re: Make mesage at end-of-recovery less scary.
Previous Message Tom Lane 2021-03-03 15:45:30 Re: contrib/cube - binary input/output handlers