| From: | Yash Jadhav <yash(dot)jadhav8008(at)gmail(dot)com> |
|---|---|
| To: | Koshino Taiki <koshino(at)sraoss(dot)co(dot)jp> |
| Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: Proposal: Include CHECK constraint expression in violation error DETAIL |
| Date: | 2026-11-26 06:48:42 |
| Message-ID: | CAGsfjr5FQO8mgcxG0ywAttZFGqTa-OOrrYpYS2ynirA0w_XhEQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
Went through the added code for domain check, and I guess the pattern
is similar to check constraint and is correct, tested it.
> @@ -4499,13 +4501,22 @@ ExecEvalConstraintCheck(ExprState *state, ExprEvalStep *op)
> if (!*op->d.domaincheck.checknull &&
> !DatumGetBool(*op->d.domaincheck.checkvalue))
> {
> char *check_desc;
>
> check_desc = deparse_expression(stringToNode(op->d.domaincheck.constraint->check_expr_bin), NIL, false, false);
>
> errsave((Node *) op->d.domaincheck.escontext,
> (errcode(ERRCODE_CHECK_VIOLATION),
> errmsg("value for domain %s violates check constraint \"%s\"",
> format_type_be(op->d.domaincheck.resulttype),
> op->d.domaincheck.constraintname),
> op->d.domaincheck.constraint->name),
> check_desc ?
> errdetail("Check constraint expression: %s.",
> check_desc) : 0,
> errdomainconstraint(op->d.domaincheck.resulttype,
> op->d.domaincheck.constraintname)));
Only one thing I wanted to point out is the check for 'check_desc' in
errsave, I guess it could be removed as 'deparse_expression' which
calls 'deparse_expression_pretty' initializes the string to be
returned using palloc and on failure it reports error instead of
returning NULL so check_desc shouldn't be NULL, am I missing anything?
Regards,
Yash
On Thu, 19 Nov 2026 at 03:56, Koshino Taiki <koshino(at)sraoss(dot)co(dot)jp> wrote:
>
> > Hi,
> >
> > I updated the patch so that it applies cleanly to the latest master.
> > The conflicts in execExpr.c and sqljson_queryfuncs.out have been
> > resolved while preserving the recent changes on master.
> >
> > The relevant regression tests also pass. The updated v5 patch is
> > attached.
> >
> > Regards,
>
> Hi,
>
> Attached is v6 of the patch.
>
> This version has been rebased onto the latest master. It includes the
> expected-output updates for postgres_fdw, hstore_plpython, PL/Perl,
> PL/Python, and PL/Tcl.
>
> The patch reports the violated expression for both table and domain
> CHECK constraints. For example:
>
> ERROR: value for domain positive_int violates check constraint "positive_int_check"
> DETAIL: Check constraint expression: (VALUE > 0).
>
> I ran make check-world with PL/Perl,
> PL/Python, and PL/Tcl enabled, and all tests passed.
>
> Regards,
>
>
> Taiki Koshino<koshino(at)sraoss(dot)co(dot)jp>
> SRA OSS K.K.
> TEL: 03-5979-2701 FAX: 03-5979-2702
> URL: https://www.sraoss.co.jp/
>
>
> ________________________________
> 差出人: Koshino Taiki <koshino(at)sraoss(dot)co(dot)jp>
> 送信日時: 2026年11月18日 15:28
> 宛先: Yash Jadhav <yash(dot)jadhav8008(at)gmail(dot)com>
> CC: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
> 件名: Re: Proposal: Include CHECK constraint expression in violation error DETAIL
>
>
> > Hi,
> >
> > In addition to table CHECK constraints, I thought it would also be
> > useful to report the violated expression for domain CHECK constraints,
> > so I updated the patch to cover them as well.
> >
> > For example, given a domain with a CHECK constraint, a violation is now
> > reported as follows:
> >
> > ERROR: value for domain positive_int violates check constraint "positive_int_check"
> > DETAIL: Check constraint expression: (VALUE > 0).
> >
> > Here, VALUE denotes the value being coerced to the domain, as in the
> > original domain CHECK expression.
> >
> > I also added regression coverage for domain constraint violations and
> > updated the affected expected output files. The postgres_fdw expected
> > output fix provided by Yash is included as well.
> >
> > The updated patch is attached.
> >
> > Regards,
>
> Hi,
>
> I updated the patch so that it applies cleanly to the latest master.
> The conflicts in execExpr.c and sqljson_queryfuncs.out have been
> resolved while preserving the recent changes on master.
>
> The relevant regression tests also pass. The updated v5 patch is
> attached.
>
> Regards,
>
> Taiki Koshino<koshino(at)sraoss(dot)co(dot)jp>
> SRA OSS K.K.
> TEL: 03-5979-2701 FAX: 03-5979-2702
> URL: https://www.sraoss.co.jp/
>
>
> ________________________________
> 差出人: Koshino Taiki <koshino(at)sraoss(dot)co(dot)jp>
> 送信日時: 2026年11月18日 10:53
> 宛先: Yash Jadhav <yash(dot)jadhav8008(at)gmail(dot)com>
> CC: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
> 件名: Re: Proposal: Include CHECK constraint expression in violation error DETAIL
>
>
> > Hi Yash,
> >
> > Thank you for investigating the cfbot failures and providing the
> expected-output update.
> >
> > I incorporated your changes to
> > contrib/postgres_fdw/expected/postgres_fdw.out into the next version of
> > the patch. The failures were caused by the newly added CHECK constraint
> > expression changing the DETAIL text, while the postgres_fdw expected
> > output still contained the previous messages.
> >
> > After merging the changes, I ran:
> >
> > make -C contrib/postgres_fdw check
> >
> > and all postgres_fdw regression tests passed successfully. I will
> > include the updated expected output in the next patch version.
> >
> > Thanks again for catching the missing regression test updates.
> >
> > Regards,
>
> Hi,
>
> In addition to table CHECK constraints, I thought it would also be
> useful to report the violated expression for domain CHECK constraints,
> so I updated the patch to cover them as well.
>
> For example, given a domain with a CHECK constraint, a violation is now
> reported as follows:
>
> ERROR: value for domain positive_int violates check constraint "positive_int_check"
> DETAIL: Check constraint expression: (VALUE > 0).
>
> Here, VALUE denotes the value being coerced to the domain, as in the
> original domain CHECK expression.
>
> I also added regression coverage for domain constraint violations and
> updated the affected expected output files. The postgres_fdw expected
> output fix provided by Yash is included as well.
>
> The updated patch is attached.
>
> Regards,
>
>
> Taiki Koshino<koshino(at)sraoss(dot)co(dot)jp>
> SRA OSS K.K.
> TEL: 03-5979-2701 FAX: 03-5979-2702
> URL: https://www.sraoss.co.jp/
>
>
> ________________________________
> 差出人: Koshino Taiki <koshino(at)sraoss(dot)co(dot)jp>
> 送信日時: 2026年11月17日 17:58
> 宛先: Yash Jadhav <yash(dot)jadhav8008(at)gmail(dot)com>
> CC: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
> 件名: Re: Proposal: Include CHECK constraint expression in violation error DETAIL
>
>
> Hi Yash,
>
> Thank you for investigating the cfbot failures and providing the
> expected-output update.
>
> I incorporated your changes to
> contrib/postgres_fdw/expected/postgres_fdw.out into the next version of
> the patch. The failures were caused by the newly added CHECK constraint
> expression changing the DETAIL text, while the postgres_fdw expected
> output still contained the previous messages.
>
> After merging the changes, I ran:
>
> make -C contrib/postgres_fdw check
>
> and all postgres_fdw regression tests passed successfully. I will
> include the updated expected output in the next patch version.
>
> Thanks again for catching the missing regression test updates.
>
> Regards,
>
>
> Taiki Koshino<koshino(at)sraoss(dot)co(dot)jp>
> SRA OSS K.K.
> TEL: 03-5979-2701 FAX: 03-5979-2702
> URL: https://www.sraoss.co.jp/
>
>
> ________________________________
> 差出人: Yash Jadhav <yash(dot)jadhav8008(at)gmail(dot)com>
> 送信日時: 2026年11月15日 18:54
> 宛先: Koshino Taiki <koshino(at)sraoss(dot)co(dot)jp>
> CC: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>; Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp>
> 件名: Re: Proposal: Include CHECK constraint expression in violation error DETAIL
>
> Hi,
>
> cfbot is failing on v2 in the contrib/postgres_fdw regression test
> (Linux Autoconf, Linux Meson, and others). Its expected output still
> has the old DETAIL text for several check constraint violations.
>
> I’ve attached a patch that updates
> contrib/postgres_fdw/expected/postgres_fdw.out. I applied it on top of
> v2, and make -C contrib/postgres_fdw check passes.
>
> The attachment is named nocfbot, so cfbot doesn’t treat it as a
> replacement for the patch set. You can apply the change into your next
> version.
>
> Regards,
> Yash
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Ashutosh Bapat | 2026-11-26 06:49:49 | Re: Assertion failure in get_matching_part_pairs() with pruned partitions |
| Previous Message | Yash Jadhav | 2026-11-26 06:47:35 | Re: Proposal: Include CHECK constraint expression in violation error DETAIL |