On Mon, May 10, 2021 at 08:16:16AM +0200, Laurenz Albe wrote:
> On Mon, 2021-05-10 at 02:03 -0400, Bruce Momjian wrote:
> > When using \e in psql, if the buffer is not modified by the editor, ignore 
> > the editor contents and leave the buffer unchanged (Laurenz Albe)
> > The \ef and \ev commands also now have this behavior. DOCS SAY BUFFER IS 
> > CLEARED.
> 
> It's a bit more complicated: If you edit the current buffer with \e, the 
> buffer is
> unchanged if you quit the editor.
> However, if you edit the previous statement, a file or the definition of a 
> function
> or view, the query buffer is cleared if you quit the editor without saving.
> 
> Suggested wording:
> 
> When editing anything else than the current query buffer with \e, and you quit
> the editor, the query buffer is cleared.  This makes the behavior less 
> surprising
> and prevents the unintended re-execution of the previous statement.

OK, I figured it out.  I was confused by \p because \? says:

        test=> \?
        Query Buffer
          \e [FILE] [LINE]       edit the query buffer (or file) with external 
editor
          \ef [FUNCNAME [LINE]]  edit function definition with external editor
          \ev [VIEWNAME [LINE]]  edit view definition with external editor
-->       \p                     show the contents of the query buffer
          \r                     reset (clear) the query buffer
          ...


but the documentaton says:

       \p or \print
           Print the current query buffer to the standard output. If
-->        the current query buffer is empty, the most recently executed
-->        query is printed instead.

I wasn't aware that \e loads the previous query if the buffer is empty. 
I came up with this release note text:

        <listitem>
        <!--
        Author: Tom Lane <t...@sss.pgh.pa.us>
        2021-04-03 [55873a00e] Improve psql's behavior when the editor is 
exited withou
        -->
        
        <para>
        When editing the previous query or a file with psql's \e, ignore the
        contents if the editor exits without saving (Laurenz Albe)
        </para>
        
        <para>
        Previously, editing the previous query or a file and not saving the
        editor contents would still execute the editor contents.  The \ef and
        \ev commands also now have this behavior.
        </para>
        </listitem>

-- 
  Bruce Momjian  <br...@momjian.us>        https://momjian.us
  EDB                                      https://enterprisedb.com

  If only the physical world exists, free will is an illusion.



Reply via email to