Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hIZGU-0001GQ-18 for pgsql-hackers@arkaria.postgresql.org; Mon, 22 Apr 2019 13:45:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hIZGS-0000xs-Lc for pgsql-hackers@arkaria.postgresql.org; Mon, 22 Apr 2019 13:45:44 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hIZGS-0000wc-8x for pgsql-hackers@lists.postgresql.org; Mon, 22 Apr 2019 13:45:44 +0000 Received: from xvm-110-146.dc2.ghst.net ([46.226.110.146] helo=fetter.org) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hIZGI-0007KC-UG for pgsql-hackers@postgresql.org; Mon, 22 Apr 2019 13:45:43 +0000 Received: by fetter.org (Postfix, from userid 1001) id 1FE5540828; Mon, 22 Apr 2019 15:45:33 +0200 (CEST) Date: Mon, 22 Apr 2019 15:45:32 +0200 From: David Fetter To: Fabien COELHO Cc: Corey Huinker , PostgreSQL Development Subject: Re: [PATCH v1] Add \echo_stderr to psql Message-ID: <20190422134532.GV28936@fetter.org> References: <20190421183115.GA4311@fetter.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="LpQ9ahxlCli8rRTG" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --LpQ9ahxlCli8rRTG Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Apr 22, 2019 at 09:04:08AM +0200, Fabien COELHO wrote: > > Hello Corey, > > > > \warn ... > > > \warning ... > > > > These two seem about the best to me, drawing from the perl warn command. > > Yep, I was thinking of perl & gmake. Maybe the 4 letter option is better > because its the same length as "echo". > > > I suppose we could go the bash &2 route here, but I don't want to. > > I agree on this one. Please find attached v2, name is now \warn. How might we test this portably? Best, David. -- David Fetter http://fetter.org/ Phone: +1 415 235 3778 Remember to vote! Consider donating to Postgres: http://www.postgresql.org/about/donate --LpQ9ahxlCli8rRTG Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-Add-warn-to-psql.patch" From db987e21d0e25ce306d5482fa78d71de8454f1aa Mon Sep 17 00:00:00 2001 From: David Fetter Date: Sun, 21 Apr 2019 11:08:40 -0700 Subject: [PATCH v2] Add \warn to psql To: hackers MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------2.20.1" This is a multi-part message in MIME format. --------------2.20.1 Content-Type: text/plain; charset=UTF-8; format=fixed Content-Transfer-Encoding: 8bit - Does what it says on the label - Do we have any way to test this? diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index b86764003d..4edf8e67a1 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -1879,6 +1879,26 @@ Tue Oct 26 21:40:57 CEST 1999 + + \warn text [ ... ] + + + Prints the arguments to the standard error, separated by one + space and followed by a newline. This can be useful to + intersperse information in the output of scripts when not polluting + standard output is desired. For example: + + +=> \echo :variable +=> \warn `date` +Sun Apr 21 10:48:11 PDT 2019 + + If the first argument is an unquoted -n the trailing + newline is not written. + + + + \ef function_description line_number diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 8254d61099..9425f02005 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -319,7 +319,7 @@ exec_command(const char *cmd, status = exec_command_ef_ev(scan_state, active_branch, query_buf, true); else if (strcmp(cmd, "ev") == 0) status = exec_command_ef_ev(scan_state, active_branch, query_buf, false); - else if (strcmp(cmd, "echo") == 0 || strcmp(cmd, "qecho") == 0) + else if (strcmp(cmd, "echo") == 0 || strcmp(cmd, "warn") == 0 || strcmp(cmd, "qecho") == 0) status = exec_command_echo(scan_state, active_branch, cmd); else if (strcmp(cmd, "elif") == 0) status = exec_command_elif(scan_state, cstack, query_buf); @@ -1114,7 +1114,7 @@ exec_command_ef_ev(PsqlScanState scan_state, bool active_branch, } /* - * \echo and \qecho -- echo arguments to stdout or query output + * \echo, \warn and \qecho -- echo arguments to stdout or query output */ static backslashResult exec_command_echo(PsqlScanState scan_state, bool active_branch, const char *cmd) @@ -1129,6 +1129,8 @@ exec_command_echo(PsqlScanState scan_state, bool active_branch, const char *cmd) if (strcmp(cmd, "qecho") == 0) fout = pset.queryFout; + else if (strcmp(cmd, "warn") == 0) + fout = stderr; else fout = stdout; diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c index d6d41b51d5..2ecb8b73c1 100644 --- a/src/bin/psql/help.c +++ b/src/bin/psql/help.c @@ -207,6 +207,7 @@ slashUsage(unsigned short int pager) fprintf(output, _("Input/Output\n")); fprintf(output, _(" \\copy ... perform SQL COPY with data stream to the client host\n")); fprintf(output, _(" \\echo [STRING] write string to standard output\n")); + fprintf(output, _(" \\warn [STRING] write string to standard error\n")); fprintf(output, _(" \\i FILE execute commands from file\n")); fprintf(output, _(" \\ir FILE as \\i, but relative to location of current script\n")); fprintf(output, _(" \\o [FILE] send all query results to file or |pipe\n")); diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index bcddc7601e..383a17a7f4 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -1421,7 +1421,7 @@ psql_completion(const char *text, int start, int end) "\\t", "\\T", "\\timing", "\\unset", "\\x", - "\\w", "\\watch", + "\\w","\\warn", "\\watch", "\\z", "\\!", "\\?", NULL --------------2.20.1-- --LpQ9ahxlCli8rRTG--