1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-16 06:01:02 +03:00

Don't allow system columns in CHECK constraints, except tableoid.

Previously, arbitray system columns could be mentioned in table
constraints, but they were not correctly checked at runtime, because
the values weren't actually set correctly in the tuple.  Since it
seems easy enough to initialize the table OID properly, do that,
and continue allowing that column, but disallow the rest unless and
until someone figures out a way to make them work properly.

No back-patch, because this doesn't seem important enough to take the
risk of destabilizing the back branches.  In fact, this will pose a
dump-and-reload hazard for those upgrading from previous versions:
constraints that were accepted before but were not correctly enforced
will now either be enforced correctly or not accepted at all.  Either
could result in restore failures, but in practice I think very few
users will notice the difference, since the use case is pretty
marginal anyway and few users will be relying on features that have
not historically worked.

Amit Kapila, reviewed by Rushabh Lathia, with doc changes by me.
This commit is contained in:
Robert Haas
2013-09-23 13:31:22 -04:00
parent ff2a1f5e84
commit ba3d39c969
7 changed files with 82 additions and 1 deletions

View File

@ -551,6 +551,16 @@ scanRTEForColumn(ParseState *pstate, RangeTblEntry *rte, char *colname,
{
/* quick check to see if name could be a system column */
attnum = specialAttNum(colname);
/* In constraint check, no system column is allowed except tableOid */
if (pstate->p_expr_kind == EXPR_KIND_CHECK_CONSTRAINT &&
attnum < InvalidAttrNumber && attnum != TableOidAttributeNumber)
ereport(ERROR,
(errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
errmsg("system column \"%s\" reference in check constraint is invalid",
colname),
parser_errposition(pstate, location)));
if (attnum != InvalidAttrNumber)
{
/* now check to see if column actually is defined */