Getting psql to redisplay command after \e

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Getting psql to redisplay command after \e
Date: 2019-10-29 03:00:28
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

The attached patch teaches psql to redisplay any not-yet-executed
query text after editing with \e. The fact that you don't get to
see what you're about to execute has been complained of before,
most recently at bug #16034 [1]. In that thread I complained that
we needed some probably-not-very-portable readline functionality
to make this work. However, after experimenting with trying to
shove text back into readline's buffer, I realized that there's
not really any need to do that: we just need to print the waiting
text and then collect another line. (As a bonus, it works the
same even if you turned off readline with -n.)

It also seems like to make this not confusing, we need to regurgitate
a prompt before the query text. As an example, if I do

regression=# \e

and then put this into the edited file:

select 1,

what I see after exiting the editor is now

regression=# select 1,

Without the initial prompt it looks (to me anyway) like output
from the command, rather than something I've sort of automagically

In the cited bug, Pavlo argued that we should also print any
completed commands that get sent to the backend immediately
after \e. It'd be possible to do that by extending this patch
(basically, dump about-to-be-executed commands if need_redisplay
is still true), but on the whole I think that that would be overly
chatty, so I didn't do it.

This could stand some review and testing (e.g. does it interact
badly with any other psql features), so I'll add it to the
upcoming CF.

regards, tom lane


Attachment Content-Type Size
psql-echo-unexecuted-edited-text-1.patch text/x-diff 4.9 KB


Browse pgsql-hackers by date

  From Date Subject
Next Message Dilip Kumar 2019-10-29 03:49:14 Re: Typos and inconsistencies in code
Previous Message Thomas Munro 2019-10-29 02:33:12 Re: Preserve versions of initdb-created collations in pg_upgrade