cookConstraint dead code

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: cookConstraint dead code
Date: 2025-05-20 08:13:00
Message-ID: CACJufxFxBKGLzgN+avkG+c8vdnLNhoqMCxQ-5OnVDqWC5P7j4g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

hi.

in cookConstraint
/*
* Make sure no outside relations are referred to (this is probably dead
* code now that add_missing_from is history).
*/
if (list_length(pstate->p_rtable) != 1)
ereport(ERROR,
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
errmsg("only table \"%s\" can be referenced in check
constraint",
relname)));

looks like it indeed is dead code.
because we cannot use subquery in check constraint.
if you want to reference another table, then you need
explicit mention it, like:

CREATE TABLE t3 (a int CHECK ( (a> v3.a)));

v3. is a ColumnRef node.
transformColumnRef, refnameNamespaceItem will error out if there is no
table name
specified in FROM clause.

Browse pgsql-hackers by date

  From Date Subject
Next Message DIPESH DHAMELIYA 2025-05-20 08:14:37 Re: [PATCH] Allow parallelism for plpgsql return expression after commit 556f7b7
Previous Message Tomas Vondra 2025-05-20 07:59:53 Re: generic plans and "initial" pruning