From: Ryoga Yoshida <bt23yoshidar@oss.nttdata.com>
To: pgsql-hackers@lists.postgresql.org
Subject: Bug fix for psql's meta-command \ev
Date: Fri, 15 Sep 2023 11:37:46 +0900
Message-ID: <01419622d84ef093fd4fe585520bf03c@oss.nttdata.com> (raw)
Hi,
When a table name is specified as the first argument of \ev
meta-command, it reports the error message, the prompt string becomes
"-#" and then the following valid query fails because the psql's query
buffer contains the garbage string generated by failure of \ev. Please
see the following example.
=# \ev t
"public.t" is not a view
-# SELECT * FROM t;
ERROR: syntax error at or near "public" at character 1
STATEMENT: public.t AS
SELECT * FROM t;
I think this is a bug in psql's \ev meta-command. Even when \ev fails,
it should not leave the garbage string in psql's query buffer and the
following query should be completed successfully.
This problem can be resolved by resetting the query buffer on error. You
can see the attached source code. After that, it will result in output
like the following:
=# \ev t
"public.t" is not a view
=# SELECT * FROM t;
i
---
1
2
(2 rows)
Ryoga Yoshida
Attachments:bug_fix_for_ev_command.patch (text/x-diff, 354B) downloaddiff --git a/src/bin/psql/command.c b/src/bin/psql/command.cindex bcd8eb3538..a853bce096 100644--- a/src/bin/psql/command.c+++ b/src/bin/psql/command.c@@ -1238,6 +1238,8 @@ exec_command_ef_ev(PsqlScanState scan_state, bool active_branch,
else
status = PSQL_CMD_NEWEDIT;
}
+ else+ resetPQExpBuffer(query_buf);
free(obj_desc);
}
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-hackers@postgresql.org
Cc: bt23yoshidar@oss.nttdata.com
Subject: Re: Bug fix for psql's meta-command \ev
In-Reply-To: <01419622d84ef093fd4fe585520bf03c@oss.nttdata.com>
References: <01419622d84ef093fd4fe585520bf03c@oss.nttdata.com>
* 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