Hello
I was asked, how can be showed only failed queries in psql.
I am thinking, so it is not possible now. But implementation is very simple
What do you think about it?
bash-4.1$ psql postgres -v ECHO=error -f data.sql
INSERT 0 1
Time: 27.735 ms
INSERT 0 1
Time: 8.303 ms
psql:data.sql:3: ERROR: value too long for type character varying(2)
insert into foo values('bbb');
Time: 0.178 ms
INSERT 0 1
Time: 8.285 ms
psql:data.sql:5: ERROR: value too long for type character varying(2)
insert into foo values('ssssss');
Time: 0.422 ms
Regards
Pavel
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index 3a820fa..8354f60 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -958,6 +958,12 @@ SendQuery(const char *query)
results = NULL; /* PQclear(NULL) does nothing */
}
+ if (!OK && pset.echo == PSQL_ECHO_ERROR_QUERIES)
+ {
+ puts(query);
+ fflush(stdout);
+ }
+
/* If we made a temporary savepoint, possibly release/rollback */
if (on_error_rollback_savepoint)
{
diff --git a/src/bin/psql/settings.h b/src/bin/psql/settings.h
index 3e8328d..ed80179 100644
--- a/src/bin/psql/settings.h
+++ b/src/bin/psql/settings.h
@@ -30,6 +30,7 @@
typedef enum
{
PSQL_ECHO_NONE,
+ PSQL_ECHO_ERROR_QUERIES,
PSQL_ECHO_QUERIES,
PSQL_ECHO_ALL
} PSQL_ECHO;
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 1061992..666261f 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -712,6 +712,8 @@ echo_hook(const char *newval)
{
if (newval == NULL)
pset.echo = PSQL_ECHO_NONE;
+ else if (strcmp(newval, "error") == 0)
+ pset.echo = PSQL_ECHO_ERROR_QUERIES;
else if (strcmp(newval, "queries") == 0)
pset.echo = PSQL_ECHO_QUERIES;
else if (strcmp(newval, "all") == 0)
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 1d69b95..641cff3 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3397,6 +3397,23 @@ psql_completion(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", "error", "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 ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers