130 bool isAddConstraint);
132 bool skipValidation);
134 List *constraintList);
136static void setSchemaName(
const char *context_schema,
char **stmt_schema_name);
142 const char *colName,
Oid colType,
int32 colTypmod,
186 stmt->relation->location);
209 (
errcode(ERRCODE_DUPLICATE_TABLE),
210 errmsg(
"relation \"%s\" already exists, skipping",
211 stmt->relation->relname)));
222 if (
stmt->relation->schemaname == NULL
223 &&
stmt->relation->relpersistence != RELPERSISTENCE_TEMP)
230 cxt.
stmtType =
"CREATE FOREIGN TABLE";
257 if (
stmt->ofTypename)
262 if (
stmt->inhRelations && !
stmt->partbound)
264 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
265 errmsg(
"cannot create partitioned table as inheritance child")));
272 foreach(elements,
stmt->tableElts)
286 case T_TableLikeClause:
291 elog(
ERROR,
"unrecognized node type: %d",
303 save_alist = cxt.
alist;
323 if (strcmp(cd->colname, colname) != 0)
329 cd->is_not_null =
true;
391 Oid seqtypid,
List *seqoptions,
392 bool for_identity,
bool col_exists,
393 char **snamespace_p,
char **sname_p)
414 foreach(
option, seqoptions)
418 if (strcmp(defel->
defname,
"sequence_name") == 0)
425 else if (strcmp(defel->
defname,
"logged") == 0 ||
426 strcmp(defel->
defname,
"unlogged") == 0)
484 (
errmsg_internal(
"%s will create implicit sequence \"%s\" for serial column \"%s.%s\"",
501 if (seqpersistence == RELPERSISTENCE_TEMP)
503 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
504 errmsg(
"cannot set logged status of a temporary sequence"),
506 else if (strcmp(loggedEl->
defname,
"logged") == 0)
507 seqpersistence = RELPERSISTENCE_PERMANENT;
509 seqpersistence = RELPERSISTENCE_UNLOGGED;
571 (
Node *) attnamelist, -1));
580 *snamespace_p = snamespace;
598 bool need_notnull =
false;
599 bool disallow_noinherit_notnull =
false;
612 if (strcmp(
typname,
"smallserial") == 0 ||
613 strcmp(
typname,
"serial2") == 0)
619 else if (strcmp(
typname,
"serial") == 0 ||
620 strcmp(
typname,
"serial4") == 0)
626 else if (strcmp(
typname,
"bigserial") == 0 ||
627 strcmp(
typname,
"serial8") == 0)
641 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
642 errmsg(
"array of serial is not implemented"),
665 &snamespace, &sname);
684 castnode->
arg = (
Node *) snamenode;
699 disallow_noinherit_notnull =
true;
717 if (!disallow_noinherit_notnull)
721 switch (constraint->contype)
725 disallow_noinherit_notnull =
true;
734 saw_nullable =
false;
736 saw_identity =
false;
737 saw_generated =
false;
741 switch (constraint->contype)
744 if ((saw_nullable && column->
is_not_null) || need_notnull)
746 (
errcode(ERRCODE_SYNTAX_ERROR),
747 errmsg(
"conflicting NULL/NOT NULL declarations for column \"%s\" of table \"%s\"",
750 constraint->location)));
758 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
759 errmsg(
"not-null constraints on partitioned tables cannot be NO INHERIT"));
764 (
errcode(ERRCODE_SYNTAX_ERROR),
765 errmsg(
"conflicting NULL/NOT NULL declarations for column \"%s\" of table \"%s\"",
768 constraint->location)));
770 if (disallow_noinherit_notnull && constraint->is_no_inherit)
773 errmsg(
"conflicting NO INHERIT declarations for not-null constraints on column \"%s\"",
791 need_notnull =
false;
794 notnull_constraint = constraint;
797 else if (notnull_constraint)
799 if (constraint->conname &&
801 strcmp(notnull_constraint->
conname, constraint->conname) != 0)
802 elog(
ERROR,
"conflicting not-null constraint names \"%s\" and \"%s\"",
803 notnull_constraint->
conname, constraint->conname);
805 if (notnull_constraint->
is_no_inherit != constraint->is_no_inherit)
808 errmsg(
"conflicting NO INHERIT declarations for not-null constraints on column \"%s\"",
811 if (!notnull_constraint->
conname && constraint->conname)
812 notnull_constraint->
conname = constraint->conname;
820 (
errcode(ERRCODE_SYNTAX_ERROR),
821 errmsg(
"multiple default values specified for column \"%s\" of table \"%s\"",
824 constraint->location)));
826 Assert(constraint->cooked_expr == NULL);
837 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
838 errmsg(
"identity columns are not supported on typed tables")));
841 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
842 errmsg(
"identity columns are not supported on partitions")));
850 (
errcode(ERRCODE_SYNTAX_ERROR),
851 errmsg(
"multiple identity specifications for column \"%s\" of table \"%s\"",
854 constraint->location)));
857 typeOid, constraint->options,
861 column->
identity = constraint->generated_when;
872 (
errcode(ERRCODE_SYNTAX_ERROR),
873 errmsg(
"conflicting NULL/NOT NULL declarations for column \"%s\" of table \"%s\"",
876 constraint->location)));
883 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
884 errmsg(
"generated columns are not supported on typed tables")));
887 (
errcode(ERRCODE_SYNTAX_ERROR),
888 errmsg(
"multiple generation clauses specified for column \"%s\" of table \"%s\"",
891 constraint->location)));
892 column->
generated = ATTRIBUTE_GENERATED_STORED;
894 Assert(constraint->cooked_expr == NULL);
895 saw_generated =
true;
905 (
errcode(ERRCODE_SYNTAX_ERROR),
906 errmsg(
"conflicting NULL/NOT NULL declarations for column \"%s\" of table \"%s\"",
909 constraint->location)));
914 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
915 errmsg(
"primary key constraints are not supported on foreign tables"),
917 constraint->location)));
923 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
924 errmsg(
"unique constraints are not supported on foreign tables"),
926 constraint->location)));
927 if (constraint->keys ==
NIL)
934 elog(
ERROR,
"column exclusion constraints are not supported");
940 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
941 errmsg(
"foreign key constraints are not supported on foreign tables"),
943 constraint->location)));
963 elog(
ERROR,
"unrecognized constraint type: %d",
964 constraint->contype);
968 if (saw_default && saw_identity)
970 (
errcode(ERRCODE_SYNTAX_ERROR),
971 errmsg(
"both default and identity specified for column \"%s\" of table \"%s\"",
974 constraint->location)));
976 if (saw_default && saw_generated)
978 (
errcode(ERRCODE_SYNTAX_ERROR),
979 errmsg(
"both default and generation expression specified for column \"%s\" of table \"%s\"",
982 constraint->location)));
984 if (saw_identity && saw_generated)
986 (
errcode(ERRCODE_SYNTAX_ERROR),
987 errmsg(
"both identity and generation expression specified for column \"%s\" of table \"%s\"",
990 constraint->location)));
997 if (need_notnull && !(saw_nullable && column->
is_not_null))
1042 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1043 errmsg(
"primary key constraints are not supported on foreign tables"),
1052 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1053 errmsg(
"unique constraints are not supported on foreign tables"),
1062 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1063 errmsg(
"exclusion constraints are not supported on foreign tables"),
1076 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1077 errmsg(
"not-null constraints on partitioned tables cannot be NO INHERIT"));
1085 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1086 errmsg(
"foreign key constraints are not supported on foreign tables"),
1100 elog(
ERROR,
"invalid context for constraint type %d",
1105 elog(
ERROR,
"unrecognized constraint type: %d",
1137 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1138 errmsg(
"LIKE is not supported for creating foreign tables")));
1143 if (relation->
rd_rel->relkind != RELKIND_RELATION &&
1144 relation->
rd_rel->relkind != RELKIND_VIEW &&
1145 relation->
rd_rel->relkind != RELKIND_MATVIEW &&
1146 relation->
rd_rel->relkind != RELKIND_COMPOSITE_TYPE &&
1147 relation->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
1148 relation->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1150 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1151 errmsg(
"relation \"%s\" is invalid in LIKE clause",
1160 if (relation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
1184 for (parent_attno = 1; parent_attno <= tupleDesc->
natts;
1194 if (attribute->attisdropped)
1201 attribute->atttypmod, attribute->attcollation);
1212 if (attribute->atthasdef && attribute->attgenerated &&
1214 def->
generated = attribute->attgenerated;
1219 if (attribute->attidentity &&
1235 def->
identity = attribute->attidentity;
1240 def->
storage = attribute->attstorage;
1256 attribute->attnum)) != NULL)
1293 if (table_like_clause->
options &
1341 elog(
ERROR,
"expandTableLikeClause called on untransformed LIKE clause");
1346 constr = tupleDesc->
constr;
1365 if ((table_like_clause->
options &
1369 for (parent_attno = 1; parent_attno <= tupleDesc->
natts;
1378 if (attribute->attisdropped)
1386 if (attribute->atthasdef &&
1387 (attribute->attgenerated ?
1393 bool found_whole_row;
1396 if (this_default == NULL)
1397 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
1402 atsubcmd->
num = attmap->
attnums[parent_attno - 1];
1414 if (found_whole_row)
1416 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1417 errmsg(
"cannot convert whole-row table reference"),
1418 errdetail(
"Generation expression for column \"%s\" contains a whole-row reference to table \"%s\".",
1422 atsubcmds =
lappend(atsubcmds, atsubcmd);
1436 for (ccnum = 0; ccnum < constr->
num_check; ccnum++)
1444 bool found_whole_row;
1459 if (found_whole_row)
1461 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1462 errmsg(
"cannot convert whole-row table reference"),
1463 errdetail(
"Constraint \"%s\" contains a whole-row reference to table \"%s\".",
1483 atsubcmds =
lappend(atsubcmds, atsubcmd);
1489 ConstraintRelationId,
1515 atcmd->
cmds = atsubcmds;
1518 result =
lcons(atcmd, result);
1525 relation->
rd_rel->relhasindex)
1527 List *parent_indexes;
1532 foreach(l, parent_indexes)
1558 result =
lappend(result, index_stmt);
1569 List *parent_extstats;
1574 foreach(l, parent_extstats)
1596 result =
lappend(result, stats_stmt);
1628 ofTypename->
typeOid = ofTypeId;
1631 for (
i = 0;
i < tupdesc->
natts;
i++)
1636 if (attr->attisdropped)
1640 attr->atttypmod, attr->attcollation);
1700 elog(
ERROR,
"cache lookup failed for relation %u", source_relid);
1706 indrelid = idxrec->indrelid;
1711 elog(
ERROR,
"cache lookup failed for access method %u",
1717 Anum_pg_index_indcollation);
1726 index->relation = heapRel;
1731 index->tableSpace = NULL;
1733 index->idxcomment = NULL;
1738 index->unique = idxrec->indisunique;
1739 index->nulls_not_distinct = idxrec->indnullsnotdistinct;
1740 index->primary = idxrec->indisprimary;
1741 index->iswithoutoverlaps = (idxrec->indisprimary || idxrec->indisunique) && idxrec->indisexclusion;
1742 index->transformed =
true;
1743 index->concurrent =
false;
1744 index->if_not_exists =
false;
1745 index->reset_default_tblspc =
false;
1753 index->idxname = NULL;
1761 if (
index->primary ||
index->unique || idxrec->indisexclusion)
1771 *constraintOid = constraintId;
1776 elog(
ERROR,
"cache lookup failed for constraint %u",
1780 index->isconstraint =
true;
1781 index->deferrable = conrec->condeferrable;
1782 index->initdeferred = conrec->condeferred;
1785 if (idxrec->indisexclusion)
1791 Assert(conrec->contype == CONSTRAINT_EXCLUSION ||
1792 (
index->iswithoutoverlaps &&
1793 (conrec->contype == CONSTRAINT_PRIMARY || conrec->contype == CONSTRAINT_UNIQUE)));
1796 Anum_pg_constraint_conexclop);
1799 for (
i = 0;
i < nElems;
i++)
1811 elog(
ERROR,
"cache lookup failed for operator %u",
1828 index->isconstraint =
false;
1831 index->isconstraint =
false;
1835 Anum_pg_index_indexprs, &isnull);
1851 for (keyno = 0; keyno < idxrec->indnkeyatts; keyno++)
1870 iparam->
expr = NULL;
1876 bool found_whole_row;
1878 if (indexpr_item == NULL)
1879 elog(
ERROR,
"too few entries in indexprs list");
1881 indexpr_item =
lnext(indexprs, indexpr_item);
1890 if (found_whole_row)
1892 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1893 errmsg(
"cannot convert whole-row table reference"),
1894 errdetail(
"Index \"%s\" contains a whole-row table reference.",
1897 iparam->
name = NULL;
1898 iparam->
expr = indexkey;
1926 if (opt & INDOPTION_DESC)
1929 if ((opt & INDOPTION_NULLS_FIRST) == 0)
1934 if (opt & INDOPTION_NULLS_FIRST)
1943 for (keyno = idxrec->indnkeyatts; keyno < idxrec->indnatts; keyno++)
1960 iparam->
expr = NULL;
1964 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1965 errmsg(
"expressions are not supported in included columns")));
1974 Anum_pg_class_reloptions, &isnull);
1980 Anum_pg_index_indpred, &isnull);
1985 bool found_whole_row;
1998 if (found_whole_row)
2000 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2001 errmsg(
"cannot convert whole-row table reference"),
2002 errdetail(
"Index \"%s\" contains a whole-row table reference.",
2005 index->whereClause = pred_tree;
2045 elog(
ERROR,
"cache lookup failed for statistics object %u", source_statsid);
2050 Anum_pg_statistic_ext_stxkind);
2055 elog(
ERROR,
"stxkind is not a 1-D char array");
2059 if (enabled[
i] == STATS_EXT_NDISTINCT)
2061 else if (enabled[
i] == STATS_EXT_DEPENDENCIES)
2063 else if (enabled[
i] == STATS_EXT_MCV)
2065 else if (enabled[
i] == STATS_EXT_EXPRESSIONS)
2069 elog(
ERROR,
"unrecognized statistics kind %c", enabled[
i]);
2073 for (
i = 0;
i < statsrec->stxkeys.dim1;
i++)
2081 def_names =
lappend(def_names, selem);
2094 Anum_pg_statistic_ext_stxexprs, &isnull);
2109 bool found_whole_row;
2121 def_names =
lappend(def_names, selem);
2131 stats->
exprs = def_names;
2165 elog(
ERROR,
"cache lookup failed for collation %u", collation);
2192 elog(
ERROR,
"cache lookup failed for opclass %u", opclass);
2251 if (cxt->
pkey != NULL)
2257 foreach(lc, indexlist)
2268 foreach(k, finalindexlist)
2289 if (priorindex->
idxname == NULL)
2326 if (cxt->
pkey != NULL)
2328 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
2329 errmsg(
"multiple primary keys for table \"%s\" are not allowed",
2340 index->isconstraint =
true;
2345 if (constraint->
conname != NULL)
2348 index->idxname = NULL;
2358 index->idxcomment = NULL;
2363 index->transformed =
false;
2364 index->concurrent =
false;
2365 index->if_not_exists =
false;
2376 char *index_name = constraint->
indexname;
2382 Datum indclassDatum;
2395 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2396 errmsg(
"cannot use an existing index in CREATE TABLE"),
2404 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2405 errmsg(
"index \"%s\" does not exist", index_name),
2415 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2416 errmsg(
"index \"%s\" is already associated with a constraint",
2423 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2424 errmsg(
"index \"%s\" does not belong to table \"%s\"",
2428 if (!index_form->indisvalid)
2430 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2431 errmsg(
"index \"%s\" is not valid", index_name),
2439 if (!index_form->indisunique)
2441 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2442 errmsg(
"\"%s\" is not a unique index", index_name),
2443 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2448 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2449 errmsg(
"index \"%s\" contains expressions", index_name),
2450 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2455 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2456 errmsg(
"\"%s\" is a partial index", index_name),
2457 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2465 if (!index_form->indimmediate && !constraint->
deferrable)
2467 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2468 errmsg(
"\"%s\" is a deferrable index", index_name),
2469 errdetail(
"Cannot create a non-deferrable constraint using a deferrable index."),
2481 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2482 errmsg(
"index \"%s\" is not a btree", index_name),
2488 Anum_pg_index_indclass);
2491 for (
i = 0;
i < index_form->indnatts;
i++)
2505 Assert(attnum <= heap_rel->rd_att->natts);
2512 if (i < index_form->indnkeyatts)
2526 index_rel->
rd_rel->relam);
2527 if (indclass->
values[
i] != defopclass ||
2529 attoptions != (
Datum) 0 ||
2532 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2533 errmsg(
"index \"%s\" column number %d does not have default sorting behavior", index_name,
i + 1),
2534 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2552 index->indexOid = index_oid;
2586 foreach(lc, constraint->
keys)
2596 foreach(columns, cxt->
columns)
2630 if (nn->is_no_inherit)
2632 errcode(ERRCODE_SYNTAX_ERROR),
2633 errmsg(
"conflicting NO INHERIT declaration for not-null constraint on column \"%s\"",
2672 if (rel->
rd_rel->relkind != RELKIND_RELATION &&
2673 rel->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2674 rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2676 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2677 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2679 for (count = 0; count < rel->
rd_att->
natts; count++)
2683 char *inhname =
NameStr(inhattr->attname);
2685 if (inhattr->attisdropped)
2687 if (strcmp(
key, inhname) == 0)
2690 typid = inhattr->atttypid;
2712 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2713 errmsg(
"column \"%s\" named in key does not exist",
key),
2717 foreach(columns,
index->indexParams)
2720 if (iparam->
name && strcmp(
key, iparam->
name) == 0)
2724 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2725 errmsg(
"column \"%s\" appears twice in primary key constraint",
2730 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2731 errmsg(
"column \"%s\" appears twice in unique constraint",
2756 if (attr->attisdropped)
2763 typid = attr->atttypid;
2775 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2776 errmsg(
"column \"%s\" in WITHOUT OVERLAPS is not a range or multirange type",
key),
2784 iparam->
expr = NULL;
2803 errcode(ERRCODE_SYNTAX_ERROR),
2804 errmsg(
"constraint using WITHOUT OVERLAPS needs at least two columns"));
2807 index->accessMethod =
"gist";
2827 foreach(columns, cxt->
columns)
2860 if (rel->
rd_rel->relkind != RELKIND_RELATION &&
2861 rel->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2862 rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2864 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2865 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2867 for (count = 0; count < rel->
rd_att->
natts; count++)
2871 char *inhname =
NameStr(inhattr->attname);
2873 if (inhattr->attisdropped)
2875 if (strcmp(
key, inhname) == 0)
2895 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2896 errmsg(
"column \"%s\" named in key does not exist",
key),
2902 iparam->
expr = NULL;
2955 bool skipValidation,
bool isAddConstraint)
2989 if (!isAddConstraint)
3003 altercmd->
name = NULL;
3004 altercmd->
def = (
Node *) constraint;
3033 if (
stmt->transformed)
3054 if (
stmt->whereClause)
3065 foreach(l,
stmt->indexParams)
3098 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
3099 errmsg(
"index expressions and predicates can refer only to the table being indexed")));
3107 stmt->transformed =
true;
3128 if (
stmt->transformed)
3149 foreach(l,
stmt->exprs)
3170 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
3171 errmsg(
"statistics expressions can refer only to the table being referenced")));
3179 stmt->transformed =
true;
3196 List **actions,
Node **whereClause)
3211 if (rel->
rd_rel->relkind == RELKIND_MATVIEW)
3213 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3214 errmsg(
"rules on materialized views are not supported")));
3241 switch (
stmt->event)
3257 elog(
ERROR,
"unrecognized event type: %d",
3273 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3274 errmsg(
"rule WHERE condition cannot contain references to other relations")));
3301 foreach(l,
stmt->actions)
3343 *whereClause != NULL)
3345 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3346 errmsg(
"rules with WHERE conditions can only have SELECT, INSERT, UPDATE, or DELETE actions")));
3363 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3364 errmsg(
"conditional UNION/INTERSECT/EXCEPT statements are not implemented")));
3376 switch (
stmt->event)
3381 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3382 errmsg(
"ON SELECT rule cannot use OLD")));
3385 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3386 errmsg(
"ON SELECT rule cannot use NEW")));
3394 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3395 errmsg(
"ON INSERT rule cannot use OLD")));
3400 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3401 errmsg(
"ON DELETE rule cannot use NEW")));
3404 elog(
ERROR,
"unrecognized event type: %d",
3428 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3429 errmsg(
"cannot refer to OLD within WITH query")));
3435 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3436 errmsg(
"cannot refer to NEW within WITH query")));
3464 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3465 errmsg(
"conditional UNION/INTERSECT/EXCEPT statements are not implemented")));
3473 newactions =
lappend(newactions, top_subqry);
3478 *actions = newactions;
3502 const char *queryString,
3503 List **beforeStmts,
List **afterStmts)
3513 bool skipValidation =
true;
3534 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
3536 cxt.
stmtType =
"ALTER FOREIGN TABLE";
3565 foreach(lcmd,
stmt->cmds)
3582 skipValidation =
false;
3590 newcmds =
lappend(newcmds, cmd);
3603 skipValidation =
false;
3606 elog(
ERROR,
"unrecognized node type: %d",
3637 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3638 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
3660 newcmds =
lappend(newcmds, cmd);
3677 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3678 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
3686 newcmds =
lappend(newcmds, cmd);
3710 if (strcmp(def->
defname,
"generated") == 0)
3711 newdef =
lappend(newdef, def);
3713 newseqopts =
lappend(newseqopts, def);
3719 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3720 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
3732 seqstmt->
options = newseqopts;
3748 newcmds =
lappend(newcmds, cmd);
3762 newcmds =
lappend(newcmds, cmd);
3772 newcmds =
lappend(newcmds, cmd);
3781 save_alist = cxt.
alist;
3795 foreach(l, cxt.
alist)
3810 newcmd->
def = (
Node *) idxstmt;
3811 newcmds =
lappend(newcmds, newcmd);
3824 newcmds =
lappend(newcmds, newcmd);
3831 newcmds =
lappend(newcmds, newcmd);
3838 newcmds =
lappend(newcmds, newcmd);
3847 stmt->cmds = newcmds;
3849 *beforeStmts = cxt.
blist;
3869 bool saw_deferrability =
false;
3870 bool saw_initially =
false;
3871 bool saw_enforced =
false;
3874#define SUPPORTS_ATTRS(node) \
3875 ((node) != NULL && \
3876 ((node)->contype == CONSTR_PRIMARY || \
3877 (node)->contype == CONSTR_UNIQUE || \
3878 (node)->contype == CONSTR_EXCLUSION || \
3879 (node)->contype == CONSTR_FOREIGN))
3881 foreach(clist, constraintList)
3886 elog(
ERROR,
"unrecognized node type: %d",
3893 (
errcode(ERRCODE_SYNTAX_ERROR),
3894 errmsg(
"misplaced DEFERRABLE clause"),
3896 if (saw_deferrability)
3898 (
errcode(ERRCODE_SYNTAX_ERROR),
3899 errmsg(
"multiple DEFERRABLE/NOT DEFERRABLE clauses not allowed"),
3901 saw_deferrability =
true;
3908 (
errcode(ERRCODE_SYNTAX_ERROR),
3909 errmsg(
"misplaced NOT DEFERRABLE clause"),
3911 if (saw_deferrability)
3913 (
errcode(ERRCODE_SYNTAX_ERROR),
3914 errmsg(
"multiple DEFERRABLE/NOT DEFERRABLE clauses not allowed"),
3916 saw_deferrability =
true;
3918 if (saw_initially &&
3921 (
errcode(ERRCODE_SYNTAX_ERROR),
3922 errmsg(
"constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3929 (
errcode(ERRCODE_SYNTAX_ERROR),
3930 errmsg(
"misplaced INITIALLY DEFERRED clause"),
3934 (
errcode(ERRCODE_SYNTAX_ERROR),
3935 errmsg(
"multiple INITIALLY IMMEDIATE/DEFERRED clauses not allowed"),
3937 saw_initially =
true;
3943 if (!saw_deferrability)
3947 (
errcode(ERRCODE_SYNTAX_ERROR),
3948 errmsg(
"constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3955 (
errcode(ERRCODE_SYNTAX_ERROR),
3956 errmsg(
"misplaced INITIALLY IMMEDIATE clause"),
3960 (
errcode(ERRCODE_SYNTAX_ERROR),
3961 errmsg(
"multiple INITIALLY IMMEDIATE/DEFERRED clauses not allowed"),
3963 saw_initially =
true;
3968 if (lastprimarycon == NULL ||
3971 (
errcode(ERRCODE_SYNTAX_ERROR),
3972 errmsg(
"misplaced ENFORCED clause"),
3976 (
errcode(ERRCODE_SYNTAX_ERROR),
3977 errmsg(
"multiple ENFORCED/NOT ENFORCED clauses not allowed"),
3979 saw_enforced =
true;
3984 if (lastprimarycon == NULL ||
3987 (
errcode(ERRCODE_SYNTAX_ERROR),
3988 errmsg(
"misplaced NOT ENFORCED clause"),
3992 (
errcode(ERRCODE_SYNTAX_ERROR),
3993 errmsg(
"multiple ENFORCED/NOT ENFORCED clauses not allowed"),
3995 saw_enforced =
true;
4005 lastprimarycon = con;
4007 saw_deferrability =
false;
4008 saw_initially =
false;
4009 saw_enforced =
false;
4037 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4038 errmsg(
"collations are not supported by type %s",
4094 foreach(elements, schemaElts)
4100 case T_CreateSeqStmt:
4144 case T_CreateTrigStmt:
4158 elog(
ERROR,
"unrecognized node type: %d",
4181 if (*stmt_schema_name == NULL)
4182 *stmt_schema_name =
unconstify(
char *, context_schema);
4183 else if (strcmp(context_schema, *stmt_schema_name) != 0)
4185 (
errcode(ERRCODE_INVALID_SCHEMA_DEFINITION),
4186 errmsg(
"CREATE specifies a schema (%s) "
4187 "different from the one being created (%s)",
4188 *stmt_schema_name, context_schema)));
4203 switch (parentRel->
rd_rel->relkind)
4205 case RELKIND_PARTITIONED_TABLE:
4208 if (cmd->
bound != NULL)
4212 case RELKIND_PARTITIONED_INDEX:
4218 if (cmd->
bound != NULL)
4220 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4221 errmsg(
"\"%s\" is not a partitioned table",
4224 case RELKIND_RELATION:
4227 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4228 errmsg(
"table \"%s\" is not partitioned",
4234 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4235 errmsg(
"index \"%s\" is not partitioned",
4240 elog(
ERROR,
"\"%s\" is not a partitioned table or index",
4274 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4275 errmsg(
"a hash-partitioned table may not have a default partition")));
4291 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4292 errmsg(
"invalid bound specification for a hash partition"),
4295 if (spec->modulus <= 0)
4297 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4298 errmsg(
"modulus for hash partition must be an integer value greater than zero")));
4300 Assert(spec->remainder >= 0);
4302 if (spec->remainder >= spec->modulus)
4304 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4305 errmsg(
"remainder for hash partition must be less than modulus")));
4317 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4318 errmsg(
"invalid bound specification for a list partition"),
4322 if (
key->partattrs[0] != 0)
4324 key->partattrs[0],
false);
4336 foreach(cell, spec->listdatums)
4344 colname, coltype, coltypmod,
4370 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4371 errmsg(
"invalid bound specification for a range partition"),
4376 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4377 errmsg(
"FROM must specify exactly one value per partitioning column")));
4380 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4381 errmsg(
"TO must specify exactly one value per partitioning column")));
4395 elog(
ERROR,
"unexpected partition strategy: %d", (
int) strategy);
4448 else if (strcmp(
"minvalue",
cname) == 0)
4454 else if (strcmp(
"maxvalue",
cname) == 0)
4471 if (
key->partattrs[
i] != 0)
4473 key->partattrs[
i],
false);
4492 if (
value->constisnull)
4494 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4495 errmsg(
"cannot specify NULL in range bound")));
4504 result =
lappend(result, prd);
4532 if (kind == prd->
kind)
4543 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4544 errmsg(
"every bound following MAXVALUE must also be MAXVALUE"),
4550 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4551 errmsg(
"every bound following MINVALUE must also be MINVALUE"),
4563 const char *colName,
Oid colType,
int32 colTypmod,
4593 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4594 errmsg(
"specified value cannot be cast to type %s for column \"%s\"",
4609 elog(
ERROR,
"could not evaluate partition bound expression");
4619 ((
Const *)
value)->constcollid = partCollation;
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Oid get_index_am_oid(const char *amname, bool missing_ok)
#define DatumGetArrayTypeP(X)
void deconstruct_array_builtin(ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
AttrMap * build_attrmap_by_name(TupleDesc indesc, TupleDesc outdesc, bool missing_ok)
#define AttributeNumberIsValid(attributeNumber)
#define InvalidAttrNumber
char * get_tablespace_name(Oid spc_oid)
#define TextDatumGetCString(d)
#define unconstify(underlying_type, expr)
#define InvalidSubTransactionId
#define Assert(condition)
#define OidIsValid(objectId)
Expr * evaluate_expr(Expr *expr, Oid result_type, int32 result_typmod, Oid result_collation)
List * sequence_options(Oid relid)
void errorConflictingDefElem(DefElem *defel, ParseState *pstate)
int errmsg_internal(const char *fmt,...)
int errdetail(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
bool equal(const void *a, const void *b)
const FormData_pg_attribute * SystemAttributeByName(const char *attname)
const FormData_pg_attribute * SystemAttributeDefinition(AttrNumber attno)
#define HeapTupleIsValid(tuple)
#define DEFAULT_INDEX_TYPE
void index_close(Relation relation, LOCKMODE lockmode)
Relation index_open(Oid relationId, LOCKMODE lockmode)
char * ChooseRelationName(const char *name1, const char *name2, const char *label, Oid namespaceid, bool isconstraint)
Oid GetDefaultOpClass(Oid type_id, Oid am_id)
if(TABLE==NULL||TABLE_index==NULL)
List * lappend(List *list, void *datum)
List * list_concat(List *list1, const List *list2)
List * list_copy(const List *oldlist)
List * lcons(void *datum, List *list)
void list_free(List *list)
#define AccessExclusiveLock
char * get_rel_name(Oid relid)
AttrNumber get_attnum(Oid relid, const char *attname)
bool type_is_range(Oid typid)
Datum get_attoptions(Oid relid, int16 attnum)
Oid get_rel_namespace(Oid relid)
Oid get_typcollation(Oid typid)
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
char * get_namespace_name(Oid nspid)
Oid get_atttype(Oid relid, AttrNumber attnum)
Oid get_relname_relid(const char *relname, Oid relnamespace)
bool type_is_multirange(Oid typid)
Alias * makeAlias(const char *aliasname, List *colnames)
DefElem * makeDefElem(char *name, Node *arg, int location)
FromExpr * makeFromExpr(List *fromlist, Node *quals)
ColumnDef * makeColumnDef(const char *colname, Oid typeOid, int32 typmod, Oid collOid)
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
FuncCall * makeFuncCall(List *name, List *args, CoercionForm funcformat, int location)
Constraint * makeNotNullConstraint(String *colname)
TypeName * makeTypeNameFromOid(Oid typeOid, int32 typmod)
char * pstrdup(const char *in)
void pfree(void *pointer)
Oid RangeVarGetAndCheckCreationNamespace(RangeVar *relation, LOCKMODE lockmode, Oid *existing_relation_id)
void RangeVarAdjustRelationPersistence(RangeVar *newRelation, Oid nspid)
Oid RangeVarGetCreationNamespace(const RangeVar *newRelation)
RangeVar * makeRangeVarFromNameList(const List *names)
Oid exprType(const Node *expr)
int exprLocation(const Node *expr)
#define IsA(nodeptr, _type_)
#define castNode(_type_, nodeptr)
ObjectType get_relkind_objtype(char relkind)
#define ObjectAddressSet(addr, class_id, object_id)
char * nodeToString(const void *obj)
Node * transformWhereClause(ParseState *pstate, Node *clause, ParseExprKind exprKind, const char *constructName)
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
void assign_expr_collations(ParseState *pstate, Node *expr)
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
void cancel_parser_errposition_callback(ParseCallbackState *pcbstate)
void free_parsestate(ParseState *pstate)
int parser_errposition(ParseState *pstate, int location)
void setup_parser_errposition_callback(ParseCallbackState *pcbstate, ParseState *pstate, int location)
ParseState * make_parsestate(ParseState *parentParseState)
@ EXPR_KIND_STATS_EXPRESSION
@ EXPR_KIND_INDEX_EXPRESSION
@ EXPR_KIND_PARTITION_BOUND
@ EXPR_KIND_INDEX_PREDICATE
@ EXPR_KIND_ALTER_COL_TRANSFORM
ParseNamespaceItem * addRangeTableEntryForRelation(ParseState *pstate, Relation rel, int lockmode, Alias *alias, bool inh, bool inFromCl)
void addNSItemToQuery(ParseState *pstate, ParseNamespaceItem *nsitem, bool addToJoinList, bool addToRelNameSpace, bool addToVarNameSpace)
char * FigureIndexColname(Node *node)
Oid LookupCollation(ParseState *pstate, List *collnames, int location)
Type typenameType(ParseState *pstate, const TypeName *typeName, int32 *typmod_p)
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
static void generateSerialExtraStmts(CreateStmtContext *cxt, ColumnDef *column, Oid seqtypid, List *seqoptions, bool for_identity, bool col_exists, char **snamespace_p, char **sname_p)
List * transformCreateStmt(CreateStmt *stmt, const char *queryString)
IndexStmt * transformIndexStmt(Oid relid, IndexStmt *stmt, const char *queryString)
List * transformCreateSchemaStmtElements(List *schemaElts, const char *schemaName)
static void transformColumnType(CreateStmtContext *cxt, ColumnDef *column)
static void transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
void transformRuleStmt(RuleStmt *stmt, const char *queryString, List **actions, Node **whereClause)
static void transformIndexConstraints(CreateStmtContext *cxt)
static List * get_collation(Oid collation, Oid actual_datatype)
static IndexStmt * transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
AlterTableStmt * transformAlterTableStmt(Oid relid, AlterTableStmt *stmt, const char *queryString, List **beforeStmts, List **afterStmts)
static void transformTableLikeClause(CreateStmtContext *cxt, TableLikeClause *table_like_clause)
static void transformConstraintAttrs(CreateStmtContext *cxt, List *constraintList)
List * expandTableLikeClause(RangeVar *heapRel, TableLikeClause *table_like_clause)
static void transformTableConstraint(CreateStmtContext *cxt, Constraint *constraint)
static List * get_opclass(Oid opclass, Oid actual_datatype)
static List * transformPartitionRangeBounds(ParseState *pstate, List *blist, Relation parent)
static void transformPartitionCmd(CreateStmtContext *cxt, PartitionCmd *cmd)
static void setSchemaName(const char *context_schema, char **stmt_schema_name)
CreateStatsStmt * transformStatsStmt(Oid relid, CreateStatsStmt *stmt, const char *queryString)
static void validateInfiniteBounds(ParseState *pstate, List *blist)
static Const * transformPartitionBoundValue(ParseState *pstate, Node *val, const char *colName, Oid colType, int32 colTypmod, Oid partCollation)
static void transformCheckConstraints(CreateStmtContext *cxt, bool skipValidation)
static void transformOfType(CreateStmtContext *cxt, TypeName *ofTypename)
static CreateStatsStmt * generateClonedExtStatsStmt(RangeVar *heapRel, Oid heapRelid, Oid source_statsid, const AttrMap *attmap)
PartitionBoundSpec * transformPartitionBound(ParseState *pstate, Relation parent, PartitionBoundSpec *spec)
static void transformFKConstraints(CreateStmtContext *cxt, bool skipValidation, bool isAddConstraint)
IndexStmt * generateClonedIndexStmt(RangeVar *heapRel, Relation source_idx, const AttrMap *attmap, Oid *constraintOid)
#define SUPPORTS_ATTRS(node)
@ PARTITION_STRATEGY_HASH
@ PARTITION_STRATEGY_LIST
@ PARTITION_STRATEGY_RANGE
@ CONSTR_ATTR_NOT_DEFERRABLE