Re: Add schema-qualified relnames in constraint error messages.

From: "Shulgin, Oleksandr" <oleksandr(dot)shulgin(at)zalando(dot)de>
To: Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Petr Korobeinikov <pkorobeinikov(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Add schema-qualified relnames in constraint error messages.
Date: 2016-01-06 14:02:34
Message-ID: CACACo5Rh1G-YKCr4X3sWkb6dzCuJcMrxJ8hABymtEmw67HECpw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Jan 6, 2016 at 5:06 AM, Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com> wrote:

> On 1/5/16 9:16 PM, Tom Lane wrote:
>
>> Jim Nasby <Jim(dot)Nasby(at)bluetreble(dot)com> writes:
>>
>>> FWIW, I suspect very few people know about the verbosity setting (I
>>> didn't until a few months ago...) Maybe psql should hint about it the
>>> first time an error is reported in a session.
>>>
>>
>> Actually, what'd be really handy IMO is something to regurgitate the
>> most recent error in verbose mode, without making a permanent session
>> state change. Something like
>>
>> regression=# insert into bar values(1);
>> ERROR: insert or update on table "bar" violates foreign key constraint
>> "bar_f1_fkey"
>> DETAIL: Key (f1)=(1) is not present in table "foo".
>> regression=# \saywhat
>> ERROR: 23503: insert or update on table "bar" violates foreign key
>> constraint "bar_f1_fkey"
>> DETAIL: Key (f1)=(1) is not present in table "foo".
>> SCHEMA NAME: public
>> TABLE NAME: bar
>> CONSTRAINT NAME: bar_f1_fkey
>> LOCATION: ri_ReportViolation, ri_triggers.c:3326
>> regression=#
>>
>> Not sure how hard that would be to do within psql's current structure.
>>
>
> At first glance, it looks like it just means changing AcceptResult() to
> use PQresultErrorField in addition to PQresultErrorMessage, and stuffing
> the results somewhere. And of course adding \saywhat to the psql parser,
> but maybe someone more versed in psql code can verify that.
>
> If it is that simple, looks like another good beginner hacker task. :)

Sorry, I couldn't resist it: I was too excited to learn such option
existed. :-)

Please find attached a POC patch, using \errverbose for the command name.
Unfortunately, I didn't see a good way to contain the change in psql only
and had to change libpq, adding new interface PQresultBuildErrorMessage().
Also, what I don't like very much is that we need to keep track of the last
result from last SendQuery() in psql's pset. So in my view this is sort of
a dirty hack that works nonetheless.

Cheers!
--
Alex

Attachment Content-Type Size
0001-POC-errverbose-in-psql.patch text/x-patch 12.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2016-01-06 14:50:25 Re: Regression caused by recent change to initdb?
Previous Message Thom Brown 2016-01-06 11:37:41 Re: Optimization for updating foreign tables in Postgres FDW