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 1qv00K-002WPe-2Y for pgsql-general@arkaria.postgresql.org; Mon, 23 Oct 2023 18:50:20 +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 1qv00I-00DrDA-0e for pgsql-general@arkaria.postgresql.org; Mon, 23 Oct 2023 18:50:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qv00H-00DrCa-L2 for pgsql-general@lists.postgresql.org; Mon, 23 Oct 2023 18:50:18 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qv00F-002JhX-Kv for pgsql-general@lists.postgresql.org; Mon, 23 Oct 2023 18:50:17 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 39NIoDei410257; Mon, 23 Oct 2023 14:50:13 -0400 From: Tom Lane To: Merlin Moncure cc: pgsql-general Subject: Re: psql \r and \e -- what does clearing the query buffer actually do? In-reply-to: References: Comments: In-reply-to Merlin Moncure message dated "Mon, 23 Oct 2023 13:27:24 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <410255.1698087013.1@sss.pgh.pa.us> Date: Mon, 23 Oct 2023 14:50:13 -0400 Message-ID: <410256.1698087013@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Merlin Moncure 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