Re: Check-out mutable functions in check constraints

From: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
To: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Check-out mutable functions in check constraints
Date: 2019-07-12 11:14:57
Message-ID: 20190712111457.ekkcgx5mpkxl2ooh@development
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Jul 12, 2019 at 03:44:58PM +0900, Kyotaro Horiguchi wrote:
>Hello.
>
>As mentioned in the following message:
>
>https://www.postgresql.org/message-id/20190712.150527.145133646.horikyota.ntt%40gmail.com
>
>Mutable function are allowed in check constraint expressions but
>it is not right. The attached is a proposed fix for it including
>regression test.
>

I think the comment in parse_expr.c is wrong:

/*
* All SQL value functions are stable so we reject them in check
* constraint expressions.
*/
if (pstate->p_expr_kind == EXPR_KIND_CHECK_CONSTRAINT)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("mutable functions are not allowed in check constraints")));

At first it claims SQL value functions are stable, but then rejects them
with a message that they're mutable.

Also, the other places use "cannot ..." messages:

case EXPR_KIND_COLUMN_DEFAULT:
err = _("cannot use column reference in DEFAULT expression");
break;

so maybe these new checks should use the same style.

regards

--
Tomas Vondra http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Sehrope Sarkuni 2019-07-12 11:26:21 Re: [Proposal] Table-level Transparent Data Encryption (TDE) and Key Management Service (KMS)
Previous Message Tomas Vondra 2019-07-12 11:11:26 Re: Check-out mutable functions in check constraints