pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Merlin Moncure <mmoncure@gmail.com>
Cc: pgsql-general <pgsql-general@lists.postgresql.org>
Subject: Re: psql \r and \e -- what does clearing the query buffer actually do?
Date: Mon, 23 Oct 2023 14:50:13 -0400
Message-ID: <410256.1698087013@sss.pgh.pa.us> (raw)
In-Reply-To: <CAHyXU0zzvirqhp_4ioipOKRGFc8rvt1RO3sVXNJxzx-LHCdTzA@mail.gmail.com>
References: <CAHyXU0zzvirqhp_4ioipOKRGFc8rvt1RO3sVXNJxzx-LHCdTzA@mail.gmail.com>

Merlin Moncure <mmoncure@gmail.com> writes:
> \r (clear 'query buffer'):  Other than dutifully reporting that the query
> buffer has been cleared, I cannot for the life of me detect any observable
> behavior.

Uh ... surely there's a lot.  For example:

regression=# foo
regression-# bar;
ERROR:  syntax error at or near "foo"
LINE 1: foo
        ^
regression=# foo
regression-# \r
Query buffer reset (cleared).
regression=# bar;
ERROR:  syntax error at or near "bar"
LINE 1: bar;
        ^
regression=# 

> Perhaps, it is reset, only to re-reset to last known prompt when prompt
> returned, but,
> \r\e
> ...claims to rest but the query buffer still contains the last executed
> command, which will then run with :q! in vim.

What \r clears is the current (active) input buffer.  \e is documented
thus:

    If no filename is given, the current query buffer is copied to a
    temporary file which is then edited in the same fashion. Or, if the
    current query buffer is empty, the most recently executed query is
    copied to a temporary file and edited in the same fashion.

So \r\e will indeed result in editing the previous query.

> Regarding \e, things mostly work sanely, except that there is no way to not
> run a query except to explicitly write a blank buffer back, say with vim
> :wq after deleting all the lines in the buffer..

It's sufficient to get rid of any trailing semicolon in the editor.
Again, the man page's discussion of \e seems to me to cover this.
If you want to suggest some adjustments to make it clearer, we
could discuss that.

			regards, tom lane





view thread (3+ messages)  latest in thread

Message-ID: <410256.1698087013@sss.pgh.pa.us>
Permalink:  ../410256.1698087013@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/410256.1698087013@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, mmoncure@gmail.com
  Subject: Re: psql \r and \e -- what does clearing the query buffer actually do?
  In-Reply-To: <410256.1698087013@sss.pgh.pa.us>
  References: <CAHyXU0zzvirqhp_4ioipOKRGFc8rvt1RO3sVXNJxzx-LHCdTzA@mail.gmail.com> <410256.1698087013@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox