2014-06-30 11:20 GMT+02:00 Rajeev rastogi <rajeev.rast...@huawei.com>:

>  On 30 June 2014 12:24, Pavel Stehule Wrote:
>
>
>
> >>I have reviewed this patch. Please find my review comments below:
>
> >>1.     Command start-up option (e.g. -a/--echo-all for --ECHO=all), for
> new functionality is not provided.
>
> >all not options entered via psql variables has psql option and psql
> comment. I'll plan add new decription to --help-variables list.
>
> >If it is necessary I can add long option --echo-errors, I didn't a good
> char for short option. Any idea?
>
>
>
> But the new option we are adding are on a track of existing option, so
> better we add start-up option for this also.
>
> Yeah long option –echo-errors seems to be fine to me also. For short
> option, I think we can use “-b” stands for blunder. This is the closest one
> I could think of.
>

fixed

see a attachment pls


>
>
> >>2.     New Command start-up option should be added in "psql --help" as
> well as in documentation.
>
> >depends on previous,
>
> Right.
>
> >>Also as I understand, this new option is kind of sub-set of existing
> option (ECHO=query), so should not we display
>
> >>query string in the same format as it was getting printed earlier.
>
> >>Though I also feel that prefixing query with STATEMENT word will be
> helpful to grep but at the same time I am worried
>
> >>about inconsistency with existing option.
>
>
>
> >This is question. And I am not strong in feeling what should be
> preferred. But still I am inclined to prefer a variant with STATEMENT
> prefix. Mode with -a is used with different purpose than mode "show errors
> only" - and output with prefix is much
>
> > more consistent with log entry - and displaying error. So I agree, so
> there is potential inconsistency (but nowhere is output defined), but this
> output is more practical, when you are concentrated to error's processing.
>
> Yeah right, I just wanted to raise point to provoke other thought to see
> if anyone having different opinion. If no objection from others, we can go
> ahead with the current prefixing approach.
>
ok, we can wait two days

Regards

Pavel





>  *Thanks and Regards,*
>
> *Kumar Rajeev Rastogi*
>
commit e05f23c69db53cefa0c3438c5eaeec11e5fa05b0
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..ccaf1c3 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 a 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>error</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..0128060 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 sent to server\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

Reply via email to