diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2019-07-05 12:32:36 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2019-07-05 12:32:36 -0400 |
commit | 02e95a5049f7933cbde1dacf401604ea3fc02aa5 (patch) | |
tree | a9d0c9c0645dbc17c16c2cba4c47d58eacc99b7e /src/bin/psql/command.c | |
parent | e8fdcacc6cbeed7d1a2175c5eddf0b162e0cb7c4 (diff) | |
download | postgresql-02e95a5049f7933cbde1dacf401604ea3fc02aa5.tar.gz postgresql-02e95a5049f7933cbde1dacf401604ea3fc02aa5.zip |
Add \warn command to psql.
This is like \echo except that the text is sent to stderr not stdout.
In passing, fix a pre-existing bug in \echo and \qecho: per documentation
the -n switch should only be recognized when it is the first argument,
but actually any argument matching "-n" was treated as a switch.
(Should we back-patch that?)
David Fetter (bug fix by me), reviewed by Fabien Coelho
Discussion: https://postgr.es/m/20190421183115.GA4311@fetter.org
Diffstat (limited to 'src/bin/psql/command.c')
-rw-r--r-- | src/bin/psql/command.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 66e1aec011a..c0a7a5566eb 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -319,7 +319,8 @@ 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, "qecho") == 0 || + strcmp(cmd, "warn") == 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 +1115,7 @@ exec_command_ef_ev(PsqlScanState scan_state, bool active_branch, } /* - * \echo and \qecho -- echo arguments to stdout or query output + * \echo, \qecho, and \warn -- echo arguments to stdout, query output, or stderr */ static backslashResult exec_command_echo(PsqlScanState scan_state, bool active_branch, const char *cmd) @@ -1129,13 +1130,15 @@ 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; while ((value = psql_scan_slash_option(scan_state, OT_NORMAL, "ed, false))) { - if (!quoted && strcmp(value, "-n") == 0) + if (first && !no_newline && !quoted && strcmp(value, "-n") == 0) no_newline = true; else { |