2014-06-30 13:01 GMT+02:00 Abhijit Menon-Sen <a...@2ndquadrant.com>: > At 2014-06-30 12:48:30 +0200, pavel.steh...@gmail.com wrote: > > > > + <para> > > + Print a failed SQL commands to standard error output. This is > > + equivalent to setting the variable <varname>ECHO</varname> to > > + <literal>errors</literal>. > > No "a", just "Print failed SQL commands …". > > > - <option>-e</option>. > > + <option>-e</option>. If set to <literal>error</literal> then > only > > + failed queries are displayed. > > Should be "errors" here, not "error". > > > printf(_(" -a, --echo-all echo all input from > script\n")); > > + printf(_(" -b --echo-errors echo failed commands sent to > server\n")); > > printf(_(" -e, --echo-queries echo commands sent to > server\n")); > > Should have a comma after -b to match other options. Also I would remove > "sent to server" from the description: "echo failed commands" is fine. >
fixed > > Otherwise looks fine. I see no reason to wait for further feedback, so > I'll mark this ready for committer if you make the above corrections. > > At some point, you should probably also update your --help-variables > patch to add this new value to the description of ECHO. > I have it in TODO. But I don't would to introduce a dependency between these patches - so when first patch will be committed, than I update second patch Regards Pavel > > -- Abhijit >
commit 998203a2e35643430059c4d3490a176a830cfee2 Author: Pavel Stehule <pavel.steh...@gooddata.com> Date: Mon Jun 30 12:39:42 2014 +0200 new -b, --echo-errors option diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index ee6ec3a..2c4cc96 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -73,6 +73,18 @@ PostgreSQL documentation </varlistentry> <varlistentry> + <term><option>-b</></term> + <term><option>--echo-errors</></term> + <listitem> + <para> + Print failed SQL commands to standard error output. This is + equivalent to setting the variable <varname>ECHO</varname> to + <literal>errors</literal>. + </para> + </listitem> + </varlistentry> + + <varlistentry> <term><option>-c <replaceable class="parameter">command</replaceable></></term> <term><option>--command=<replaceable class="parameter">command</replaceable></></term> <listitem> @@ -2812,7 +2824,8 @@ bar <literal>queries</literal>, <application>psql</application> merely prints all queries as they are sent to the server. The switch for this is - <option>-e</option>. + <option>-e</option>. If set to <literal>errors</literal> then only + failed queries are displayed. </para> </listitem> </varlistentry> diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index 60169a2..6551b15 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -995,6 +995,9 @@ SendQuery(const char *query) results = NULL; /* PQclear(NULL) does nothing */ } + if (!OK && pset.echo == PSQL_ECHO_ERRORS) + psql_error("STATEMENT: %s\n", query); + /* If we made a temporary savepoint, possibly release/rollback */ if (on_error_rollback_savepoint) { diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c index 3aa3c16..f8f000f 100644 --- a/src/bin/psql/help.c +++ b/src/bin/psql/help.c @@ -87,6 +87,7 @@ usage(void) printf(_("\nInput and output options:\n")); printf(_(" -a, --echo-all echo all input from script\n")); + printf(_(" -b, --echo-errors echo failed commands\n")); printf(_(" -e, --echo-queries echo commands sent to server\n")); printf(_(" -E, --echo-hidden display queries that internal commands generate\n")); printf(_(" -L, --log-file=FILENAME send session log to file\n")); diff --git a/src/bin/psql/settings.h b/src/bin/psql/settings.h index 0a60e68..453d6c8 100644 --- a/src/bin/psql/settings.h +++ b/src/bin/psql/settings.h @@ -31,6 +31,7 @@ typedef enum { PSQL_ECHO_NONE, PSQL_ECHO_QUERIES, + PSQL_ECHO_ERRORS, PSQL_ECHO_ALL } PSQL_ECHO; diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index 45653a1..3ca3f1e 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -354,6 +354,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options) {"command", required_argument, NULL, 'c'}, {"dbname", required_argument, NULL, 'd'}, {"echo-queries", no_argument, NULL, 'e'}, + {"echo-errors", no_argument, NULL, 'b'}, {"echo-hidden", no_argument, NULL, 'E'}, {"file", required_argument, NULL, 'f'}, {"field-separator", required_argument, NULL, 'F'}, @@ -402,6 +403,9 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options) case 'A': pset.popt.topt.format = PRINT_UNALIGNED; break; + case 'b': + SetVariable(pset.vars, "ECHO", "errors"); + break; case 'c': options->action_string = pg_strdup(optarg); if (optarg[0] == '\\') @@ -720,6 +724,8 @@ echo_hook(const char *newval) pset.echo = PSQL_ECHO_NONE; else if (strcmp(newval, "queries") == 0) pset.echo = PSQL_ECHO_QUERIES; + else if (strcmp(newval, "errors") == 0) + pset.echo = PSQL_ECHO_ERRORS; else if (strcmp(newval, "all") == 0) pset.echo = PSQL_ECHO_ALL; else diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index be5c3c5..8611dd2 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -3591,6 +3591,23 @@ psql_completion(const char *text, int start, int end) { matches = complete_from_variables(text, "", ""); } + else if (strcmp(prev2_wd, "\\set") == 0) + { + if (strcmp(prev_wd, "ECHO") == 0) + { + static const char *const my_list[] = + {"none", "errors", "queries", "all", NULL}; + + COMPLETE_WITH_LIST_CS(my_list); + } + else if (strcmp(prev_wd, "ECHO_HIDDEN") == 0) + { + static const char *const my_list[] = + {"noexec", "off", "on", NULL}; + + COMPLETE_WITH_LIST_CS(my_list); + } + } else if (strcmp(prev_wd, "\\sf") == 0 || strcmp(prev_wd, "\\sf+") == 0) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_functions, NULL); else if (strcmp(prev_wd, "\\cd") == 0 ||
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers