mirror of
https://github.com/postgres/postgres.git
synced 2025-06-17 17:02:08 +03:00
Allow CHECK constraints to be placed on foreign tables.
As with NOT NULL constraints, we consider that such constraints are merely reports of constraints that are being enforced by the remote server (or other underlying storage mechanism). Their only real use is to allow planner optimizations, for example in constraint-exclusion checks. Thus, the code changes here amount to little more than removal of the error that was formerly thrown for applying CHECK to a foreign table. (In passing, do a bit of cleanup of the ALTER FOREIGN TABLE reference page, which had accumulated some weird decisions about ordering etc.) Shigeru Hanada and Etsuro Fujita, reviewed by Kyotaro Horiguchi and Ashutosh Bapat.
This commit is contained in:
@ -515,21 +515,23 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
|
||||
break;
|
||||
|
||||
case CONSTR_CHECK:
|
||||
if (cxt->isforeign)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("constraints are not supported on foreign tables"),
|
||||
parser_errposition(cxt->pstate,
|
||||
constraint->location)));
|
||||
cxt->ckconstraints = lappend(cxt->ckconstraints, constraint);
|
||||
break;
|
||||
|
||||
case CONSTR_PRIMARY:
|
||||
if (cxt->isforeign)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("primary key constraints are not supported on foreign tables"),
|
||||
parser_errposition(cxt->pstate,
|
||||
constraint->location)));
|
||||
/* FALL THRU */
|
||||
|
||||
case CONSTR_UNIQUE:
|
||||
if (cxt->isforeign)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("constraints are not supported on foreign tables"),
|
||||
errmsg("unique constraints are not supported on foreign tables"),
|
||||
parser_errposition(cxt->pstate,
|
||||
constraint->location)));
|
||||
if (constraint->keys == NIL)
|
||||
@ -546,7 +548,7 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
|
||||
if (cxt->isforeign)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("constraints are not supported on foreign tables"),
|
||||
errmsg("foreign key constraints are not supported on foreign tables"),
|
||||
parser_errposition(cxt->pstate,
|
||||
constraint->location)));
|
||||
|
||||
@ -605,18 +607,35 @@ transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
|
||||
static void
|
||||
transformTableConstraint(CreateStmtContext *cxt, Constraint *constraint)
|
||||
{
|
||||
if (cxt->isforeign)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("constraints are not supported on foreign tables"),
|
||||
parser_errposition(cxt->pstate,
|
||||
constraint->location)));
|
||||
|
||||
switch (constraint->contype)
|
||||
{
|
||||
case CONSTR_PRIMARY:
|
||||
if (cxt->isforeign)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("primary key constraints are not supported on foreign tables"),
|
||||
parser_errposition(cxt->pstate,
|
||||
constraint->location)));
|
||||
cxt->ixconstraints = lappend(cxt->ixconstraints, constraint);
|
||||
break;
|
||||
|
||||
case CONSTR_UNIQUE:
|
||||
if (cxt->isforeign)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("unique constraints are not supported on foreign tables"),
|
||||
parser_errposition(cxt->pstate,
|
||||
constraint->location)));
|
||||
cxt->ixconstraints = lappend(cxt->ixconstraints, constraint);
|
||||
break;
|
||||
|
||||
case CONSTR_EXCLUSION:
|
||||
if (cxt->isforeign)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("exclusion constraints are not supported on foreign tables"),
|
||||
parser_errposition(cxt->pstate,
|
||||
constraint->location)));
|
||||
cxt->ixconstraints = lappend(cxt->ixconstraints, constraint);
|
||||
break;
|
||||
|
||||
@ -625,6 +644,12 @@ transformTableConstraint(CreateStmtContext *cxt, Constraint *constraint)
|
||||
break;
|
||||
|
||||
case CONSTR_FOREIGN:
|
||||
if (cxt->isforeign)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("foreign key constraints are not supported on foreign tables"),
|
||||
parser_errposition(cxt->pstate,
|
||||
constraint->location)));
|
||||
cxt->fkconstraints = lappend(cxt->fkconstraints, constraint);
|
||||
break;
|
||||
|
||||
|
Reference in New Issue
Block a user