From 69835bc8988812c960f4ed5aeee86b62ac73602a Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 12 Sep 2017 19:27:48 -0400 Subject: Add psql variables to track success/failure of SQL queries. This patch adds ERROR, SQLSTATE, and ROW_COUNT, which are updated after every query, as well as LAST_ERROR_MESSAGE and LAST_ERROR_SQLSTATE, which are updated only when a query fails. The expected usage of these is for scripting. Fabien Coelho, reviewed by Pavel Stehule Discussion: https://postgr.es/m/alpine.DEB.2.20.1704042158020.12290@lancre --- doc/src/sgml/ref/psql-ref.sgml | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'doc/src') diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index a74caf8a6cf..60bafa81754 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -3517,6 +3517,16 @@ bar + + ERROR + + + true if the last SQL query failed, false if + it succeeded. See also SQLSTATE. + + + + FETCH_COUNT @@ -3653,6 +3663,19 @@ bar + + LAST_ERROR_MESSAGE + LAST_ERROR_SQLSTATE + + + The primary error message and associated SQLSTATE code for the most + recent failed query in the current psql session, or + an empty string and 00000 if no error has occurred in + the current session. + + + + ON_ERROR_ROLLBACK @@ -3732,6 +3755,16 @@ bar + + ROW_COUNT + + + The number of rows returned or affected by the last SQL query, or 0 + if the query failed or did not report a row count. + + + + SERVER_VERSION_NAME SERVER_VERSION_NUM @@ -3784,6 +3817,17 @@ bar + + SQLSTATE + + + The error code (see ) associated + with the last SQL query's failure, or 00000 if it + succeeded. + + + + USER -- cgit v1.2.3