public inbox for [email protected]
help / color / mirror / Atom feedFrom: Tom Lane <[email protected]>
To: David G. Johnston <[email protected]>
Cc: Valerio Battaglia <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: How to get column, table or parameter name reporting when violating DOMAIN type constraint
Date: Sun, 26 Mar 2023 11:26:23 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAKFQuwYJtF-5Uvqo6ahKkeEAxOKta_yVb3n3at5Y=mvSgC0FrA@mail.gmail.com>
References: <CACxJNSkpT8vC0jnsfObZDargLA1vCiP-VKF2ji9y58VaAOSpVA@mail.gmail.com>
<CAKFQuwYJtF-5Uvqo6ahKkeEAxOKta_yVb3n3at5Y=mvSgC0FrA@mail.gmail.com>
"David G. Johnston" <[email protected]> writes:
> On Sunday, March 26, 2023, Valerio Battaglia <[email protected]> wrote:
>> Is there a way to obtain more detailed information about the column, table
>> or parameter that is causing the constraint violation in this scenario? I
>> would greatly appreciate any guidance or advice you could provide on this
>> matter
> What you see is what you get.
More to the point, you have the wrong mental model: a domain constraint
violation might not be associated with a table column at all.
For example,
postgres=# select (-1)::my_domain;
ERROR: value for domain my_domain violates check constraint "value_min"
There is some useful data split out into fields of the error report:
postgres=# \errverbose
ERROR: 23514: value for domain my_domain violates check constraint "value_min"
SCHEMA NAME: public
DATATYPE NAME: my_domain
CONSTRAINT NAME: value_min
LOCATION: ExecEvalConstraintCheck, execExprInterp.c:3651
... but the only context that's available is the domain name.
If you made the constraints be table check constraints, then
you'd have localization of the sort you want:
postgres=# create table t1 (col1 int check (col1 > 0));
CREATE TABLE
postgres=# insert into t1 values (-1);
ERROR: new row for relation "t1" violates check constraint "t1_col1_check"
DETAIL: Failing row contains (-1).
postgres=# \errverbose
ERROR: 23514: new row for relation "t1" violates check constraint "t1_col1_check"
DETAIL: Failing row contains (-1).
SCHEMA NAME: public
TABLE NAME: t1
CONSTRAINT NAME: t1_col1_check
LOCATION: ExecConstraints, execMain.c:2023
regards, tom lane
view thread (6+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Subject: Re: How to get column, table or parameter name reporting when violating DOMAIN type constraint
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox