diff options
author | Tom Lane | 2017-09-12 23:27:48 +0000 |
---|---|---|
committer | Tom Lane | 2017-09-12 23:27:48 +0000 |
commit | 69835bc8988812c960f4ed5aeee86b62ac73602a (patch) | |
tree | 396db4b17f3219debd841d3af6e8b1f493357506 /doc/src | |
parent | 6e7baa322773ff8c79d4d8883c99fdeff5bfa679 (diff) |
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
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/ref/psql-ref.sgml | 44 |
1 files changed, 44 insertions, 0 deletions
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 @@ -3518,6 +3518,16 @@ bar </varlistentry> <varlistentry> + <term><varname>ERROR</varname></term> + <listitem> + <para> + <literal>true</> if the last SQL query failed, <literal>false</> if + it succeeded. See also <varname>SQLSTATE</>. + </para> + </listitem> + </varlistentry> + + <varlistentry> <term><varname>FETCH_COUNT</varname></term> <listitem> <para> @@ -3654,6 +3664,19 @@ bar </varlistentry> <varlistentry> + <term><varname>LAST_ERROR_MESSAGE</varname></term> + <term><varname>LAST_ERROR_SQLSTATE</varname></term> + <listitem> + <para> + The primary error message and associated SQLSTATE code for the most + recent failed query in the current <application>psql</> session, or + an empty string and <literal>00000</> if no error has occurred in + the current session. + </para> + </listitem> + </varlistentry> + + <varlistentry> <term> <varname>ON_ERROR_ROLLBACK</varname> <indexterm> @@ -3733,6 +3756,16 @@ bar </varlistentry> <varlistentry> + <term><varname>ROW_COUNT</varname></term> + <listitem> + <para> + 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. + </para> + </listitem> + </varlistentry> + + <varlistentry> <term><varname>SERVER_VERSION_NAME</varname></term> <term><varname>SERVER_VERSION_NUM</varname></term> <listitem> @@ -3785,6 +3818,17 @@ bar </varlistentry> <varlistentry> + <term><varname>SQLSTATE</varname></term> + <listitem> + <para> + The error code (see <xref linkend="errcodes-appendix">) associated + with the last SQL query's failure, or <literal>00000</> if it + succeeded. + </para> + </listitem> + </varlistentry> + + <varlistentry> <term><varname>USER</varname></term> <listitem> <para> |