Thread: pgsql: psql: Reset query buffer of \e, \ef and \ev on error

pgsql: psql: Reset query buffer of \e, \ef and \ev on error

From
Michael Paquier
Date:
psql: Reset query buffer of \e, \ef and \ev on error

If any of these commands fail during editing or pre-processing, the
command stored in the query buffer would remain around without being
executed immediately as PSQL_CMD_ERROR is returned as status.  The next
command provided by the user would run it, likely causing failures as
this could include silently some of the contents generated automatically
for views or functions.

The problems would be different depending on the psql meta-command used:
- For \ev and \ef, some errors can happen in a predictable way while
doing an object lookup or while creating an object command.  A failure
while editing is equally problematic, but the class of failures
happening in the code path of do_edit() are unlikely.  The query reset
is kept in exec_command_ef_ev() as a query may be unchanged.
- For \e, error can happen while editing.

In both cases, the query buffer is reset on error for an incorrect file
number provided, whose value check is done before filling up the query
buffer.

This is a slight change of behavior compared to the past for some of the
predictable error patterns for \ev and \ef, so for now I have made the
choice to not backpatch this commit (argument particularly available for
v11 that's going to be EOL'd soon).  Perhaps this could be revisited
later depending on the feedback of this new behavior.

Author: Ryoga Yoshida, Michael Paquier
Reviewed-by: Aleksander Alekseev, Kyotaro Horiguchi
Discussion: https://postgr.es/m/01419622d84ef093fd4fe585520bf03c@oss.nttdata.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/cb943054f3f6d67c858dd63192afaa488f8cb51e

Modified Files
--------------
src/bin/psql/command.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)