Hi
2014-07-09 7:07 GMT+02:00 Fujii Masao <masao.fu...@gmail.com>: > On Mon, Jun 30, 2014 at 8:33 PM, Pavel Stehule <pavel.steh...@gmail.com> > wrote: > > > > > > > > 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 > > $ psql -b > bin/psql: invalid option -- 'b' > Try "psql --help" for more information. > > I got this error. ISTM you forgot to add 'b' into the third argument of > getopt_long in startup.c. > > fixed > <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. > > I think that where failed queries are output should be documented here. > Otherwise users might misunderstand they are output to standard output > like ECHO=all and queries do. > > It's better to add "The switch for this is <option>-b</option>." into the > doc. > fixed > + 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); > + } > + } > > I think that adding tab-completions of psql variables is good, but > adding those of only ECHO and ECHO_HIDDEN seems half-baked. > Probably this part should be split into separate patch. > fixed please, see updated patch in attachment Thank you Regards Pavel > > Regards, > > -- > Fujii Masao >
commit a05543802d000b3e66276b5ff370787d6f5ee7e3 Author: Pavel Stehule <pavel.steh...@gooddata.com> Date: Wed Jul 9 14:03:42 2014 +0200 version 04 diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index 255e8ca..bbe5935 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,9 @@ 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 on standard error output. The switch + for this is <option>-b</option>. </para> </listitem> </varlistentry> diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index c08c813..676e268 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..5a397e8 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'}, @@ -391,7 +392,7 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options) memset(options, 0, sizeof *options); - while ((c = getopt_long(argc, argv, "aAc:d:eEf:F:h:HlL:no:p:P:qR:sStT:U:v:VwWxXz?01", + while ((c = getopt_long(argc, argv, "aAbc:d:eEf:F:h:HlL:no:p:P:qR:sStT:U:v:VwWxXz?01", long_options, &optindex)) != -1) { switch (c) @@ -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 bab0357..482a368 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -3592,6 +3592,16 @@ 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, "\\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