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

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: did447(at)gmail(dot)com
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [proposal] Add an option for returning SQLSTATE in psql error message
Date: 2018-12-02 15:13:29
Message-ID: CAFj8pRBFWn_kahD78ABGyJPrWiFNiiwm08Oz5+ahW9-kP7yJRw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

ne 2. 12. 2018 v 15:34 odesílatel didier <did447(at)gmail(dot)com> napsal:

> 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?
>
>
It looks weird. Maybe we can define a option where only SQL state will be
displayed.

Regards

Pavel

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2018-12-02 15:55:56 Re: [proposal] Add an option for returning SQLSTATE in psql error message
Previous Message Rafia Sabih 2018-12-02 15:03:03 Re: Compressed TOAST Slicing