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.