Re: Proposal: Include CHECK constraint expression in violation error DETAIL

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:47:35
Message-ID: CAGsfjr6E9-FrWtzvgKPFFmPd9BsRUMDUnJYYZj8TkOC-L6GDOw@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 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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Yash Jadhav 2026-11-26 06:48:42 Re: Proposal: Include CHECK constraint expression in violation error DETAIL
Previous Message Rui Zhao 2026-11-26 06:45:42 Re: Improve cube GiST page splits