psql 13.2 executes the query buffer no matter what when exiting the editor, even after quitting it - in which case the buffer may hold the most recently executed SQL query now.
- Start editor (
vimin my case) with
\e filenamefrom the
- Type something or not, doesn't make a difference.
- Cancel edit with
:q!to force it)
Expected behavior: go back to the state before starting the editor. (I cancelled the edit!)
Observed behavior: re-execute the last executed SQL query.
What seems to happen with
it executes (the equivalent of)
\p, so the current query buffer contains the previous command when it was empty. (Which is not visible to the user when editing a file!) The manual on
Print the current query buffer to the standard output. If the current query buffer is empty, the most recently executed query is printed instead.
Start up the editor. If a filename was provided, load the file, else, load the query buffer.
If the editor ends with a write, copy the result to the query buffer.
If the edit is cancelled (
:qin vim), don't overwrite the query buffer. (It holds the previous command now!)
Execute the query buffer. Or, to be precise, do this:
The behavior seems ok for
\p (just copy the query buffer, no harm done), but not for
\e, which can execute a command I didn't even get to see.
Is it a bug?
Either way, I would at least like to disable auto-execute when leaving the editor. But that doesn't seem to be possible. Or am I missing something?