[proposal] Add an option for returning SQLSTATE in psql error message

From: didier <did447(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: [proposal] Add an option for returning SQLSTATE in psql error message
Date: 2018-12-02 14:33:56
Message-ID: CAJRYxuKyj4zA+JGVrtx8OWAuBfE-_wN4sUMK4H49EuPed=mOBw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox
Thread:
Lists: pgsql-hackers

Hi,

Currently on error psql is printing Postgres' PQerrorMessage text, but
there's no guarantee these messages are constant between Postgres
versions and it's a pain when using psql for writing regression tests,

Prior
Disallow setting client_min_messages higher than ERROR.

a bad workaround was to discarded error, now you have to do something like
CREATE OR REPLACE FUNCTION catch_error(
query text
)
RETURNS void AS $$
DECLARE
BEGIN
EXECUTE query;
EXCEPTION WHEN OTHERS THEN
RAISE 'Query failed: %', SQLSTATE;
END;
$$LANGUAGE plpgsql;

SELECT catch_error('foo');

What about a new \whatever for setting psql error to either PQerrorMessage or
PQresultErrorField(res, PG_DIAG_SQLSTATE) if available?

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrey Borodin 2018-12-02 14:40:04 Re: [HACKERS] Can ICU be used for a database's default sort order?
Previous Message Lætitia Avrot 2018-12-02 12:46:37 Re: Markdown format output for psql, design notes