Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qgyjT-000U36-MC for pgsql-hackers@arkaria.postgresql.org; Fri, 15 Sep 2023 02:38:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qgyiS-00CPMW-DB for pgsql-hackers@arkaria.postgresql.org; Fri, 15 Sep 2023 02:37:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qgyiS-00CPM1-2U for pgsql-hackers@lists.postgresql.org; Fri, 15 Sep 2023 02:37:55 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qgyiO-004cyU-47 for pgsql-hackers@lists.postgresql.org; Fri, 15 Sep 2023 02:37:53 +0000 Received: from oss.nttdata.com (localhost [127.0.0.1]) by oss.nttdata.com (Postfix) with ESMTPA id E219E6084B for ; Fri, 15 Sep 2023 11:37:46 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at oss.nttdata.com MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=_3ff8f6b0861850b2acf96034f1ebb8e4" Content-Transfer-Encoding: 7bit Date: Fri, 15 Sep 2023 11:37:46 +0900 From: Ryoga Yoshida To: pgsql-hackers@lists.postgresql.org Subject: Bug fix for psql's meta-command \ev User-Agent: Roundcube Webmail/1.4.11 Message-ID: <01419622d84ef093fd4fe585520bf03c@oss.nttdata.com> X-Sender: bt23yoshidar@oss.nttdata.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=_3ff8f6b0861850b2acf96034f1ebb8e4 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed 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 --=_3ff8f6b0861850b2acf96034f1ebb8e4 Content-Transfer-Encoding: base64 Content-Type: text/x-diff; charset=us-ascii; name=bug_fix_for_ev_command.patch Content-Disposition: attachment; filename=bug_fix_for_ev_command.patch; size=354 ZGlmZiAtLWdpdCBhL3NyYy9iaW4vcHNxbC9jb21tYW5kLmMgYi9zcmMvYmluL3BzcWwvY29tbWFu ZC5jCmluZGV4IGJjZDhlYjM1MzguLmE4NTNiY2UwOTYgMTAwNjQ0Ci0tLSBhL3NyYy9iaW4vcHNx bC9jb21tYW5kLmMKKysrIGIvc3JjL2Jpbi9wc3FsL2NvbW1hbmQuYwpAQCAtMTIzOCw2ICsxMjM4 LDggQEAgZXhlY19jb21tYW5kX2VmX2V2KFBzcWxTY2FuU3RhdGUgc2Nhbl9zdGF0ZSwgYm9vbCBh Y3RpdmVfYnJhbmNoLAogCQkJZWxzZQogCQkJCXN0YXR1cyA9IFBTUUxfQ01EX05FV0VESVQ7CiAJ CX0KKwkJZWxzZQorCQkJcmVzZXRQUUV4cEJ1ZmZlcihxdWVyeV9idWYpOwogCiAJCWZyZWUob2Jq X2Rlc2MpOwogCX0K --=_3ff8f6b0861850b2acf96034f1ebb8e4--