121 Oid heapRelid,
Oid source_statsid);
130 bool isAddConstraint);
132 bool skipValidation);
134 List *constraintList);
136 static 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";
258 if (
stmt->ofTypename)
263 if (
stmt->inhRelations && !
stmt->partbound)
265 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
266 errmsg(
"cannot create partitioned table as inheritance child")));
273 foreach(elements,
stmt->tableElts)
287 case T_TableLikeClause:
292 elog(
ERROR,
"unrecognized node type: %d",
304 save_alist = cxt.
alist;
371 Oid seqtypid,
List *seqoptions,
372 bool for_identity,
bool col_exists,
373 char **snamespace_p,
char **sname_p)
402 foreach(
option, seqoptions)
406 if (strcmp(defel->
defname,
"sequence_name") == 0)
451 (
errmsg_internal(
"%s will create implicit sequence \"%s\" for serial column \"%s.%s\"",
523 (
Node *) attnamelist, -1));
532 *snamespace_p = snamespace;
550 bool need_notnull =
false;
563 if (strcmp(
typname,
"smallserial") == 0 ||
564 strcmp(
typname,
"serial2") == 0)
570 else if (strcmp(
typname,
"serial") == 0 ||
571 strcmp(
typname,
"serial4") == 0)
577 else if (strcmp(
typname,
"bigserial") == 0 ||
578 strcmp(
typname,
"serial8") == 0)
592 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
593 errmsg(
"array of serial is not implemented"),
616 &snamespace, &sname);
635 castnode->
arg = (
Node *) snamenode;
655 saw_nullable =
false;
657 saw_identity =
false;
658 saw_generated =
false;
667 if ((saw_nullable && column->
is_not_null) || need_notnull)
669 (
errcode(ERRCODE_SYNTAX_ERROR),
670 errmsg(
"conflicting NULL/NOT NULL declarations for column \"%s\" of table \"%s\"",
685 (
errcode(ERRCODE_SYNTAX_ERROR),
686 errmsg(
"conflicting NULL/NOT NULL declarations for column \"%s\" of table \"%s\"",
706 need_notnull =
false;
714 (
errcode(ERRCODE_SYNTAX_ERROR),
715 errmsg(
"multiple default values specified for column \"%s\" of table \"%s\"",
731 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
732 errmsg(
"identity columns are not supported on typed tables")));
735 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
736 errmsg(
"identity columns are not supported on partitions")));
744 (
errcode(ERRCODE_SYNTAX_ERROR),
745 errmsg(
"multiple identity specifications for column \"%s\" of table \"%s\"",
766 (
errcode(ERRCODE_SYNTAX_ERROR),
767 errmsg(
"conflicting NULL/NOT NULL declarations for column \"%s\" of table \"%s\"",
777 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
778 errmsg(
"generated columns are not supported on typed tables")));
781 (
errcode(ERRCODE_SYNTAX_ERROR),
782 errmsg(
"multiple generation clauses specified for column \"%s\" of table \"%s\"",
786 column->
generated = ATTRIBUTE_GENERATED_STORED;
789 saw_generated =
true;
799 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
800 errmsg(
"primary key constraints are not supported on foreign tables"),
808 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
809 errmsg(
"unique constraints are not supported on foreign tables"),
819 elog(
ERROR,
"column exclusion constraints are not supported");
825 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
826 errmsg(
"foreign key constraints are not supported on foreign tables"),
846 elog(
ERROR,
"unrecognized constraint type: %d",
851 if (saw_default && saw_identity)
853 (
errcode(ERRCODE_SYNTAX_ERROR),
854 errmsg(
"both default and identity specified for column \"%s\" of table \"%s\"",
859 if (saw_default && saw_generated)
861 (
errcode(ERRCODE_SYNTAX_ERROR),
862 errmsg(
"both default and generation expression specified for column \"%s\" of table \"%s\"",
867 if (saw_identity && saw_generated)
869 (
errcode(ERRCODE_SYNTAX_ERROR),
870 errmsg(
"both identity and generation expression specified for column \"%s\" of table \"%s\"",
880 if (need_notnull && !(saw_nullable && column->
is_not_null))
937 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
938 errmsg(
"primary key constraints are not supported on foreign tables"),
947 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
948 errmsg(
"unique constraints are not supported on foreign tables"),
957 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
958 errmsg(
"exclusion constraints are not supported on foreign tables"),
975 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
976 errmsg(
"foreign key constraints are not supported on foreign tables"),
988 elog(
ERROR,
"invalid context for constraint type %d",
993 elog(
ERROR,
"unrecognized constraint type: %d",
1018 bool process_notnull_constraints =
false;
1026 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1027 errmsg(
"LIKE is not supported for creating foreign tables")));
1032 if (relation->
rd_rel->relkind != RELKIND_RELATION &&
1033 relation->
rd_rel->relkind != RELKIND_VIEW &&
1034 relation->
rd_rel->relkind != RELKIND_MATVIEW &&
1035 relation->
rd_rel->relkind != RELKIND_COMPOSITE_TYPE &&
1036 relation->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
1037 relation->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1039 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1040 errmsg(
"relation \"%s\" is invalid in LIKE clause",
1049 if (relation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
1073 for (parent_attno = 1; parent_attno <= tupleDesc->
natts;
1083 if (attribute->attisdropped)
1090 attribute->atttypmod, attribute->attcollation);
1097 if (attribute->attnotnull)
1098 process_notnull_constraints =
true;
1109 if (attribute->atthasdef && attribute->attgenerated &&
1111 def->
generated = attribute->attgenerated;
1116 if (attribute->attidentity &&
1132 def->
identity = attribute->attidentity;
1137 def->
storage = attribute->attstorage;
1153 attribute->attnum)) != NULL)
1179 if ((table_like_clause->
options &
1184 process_notnull_constraints)
1249 List *parent_extstats;
1254 foreach(l, parent_extstats)
1309 bool at_pushed =
false;
1320 elog(
ERROR,
"expandTableLikeClause called on untransformed LIKE clause");
1325 constr = tupleDesc->
constr;
1344 if ((table_like_clause->
options &
1348 for (parent_attno = 1; parent_attno <= tupleDesc->
natts;
1357 if (attribute->attisdropped)
1365 if (attribute->atthasdef &&
1366 (attribute->attgenerated ?
1372 bool found_whole_row;
1375 if (this_default == NULL)
1376 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
1381 atsubcmd->
num = attmap->
attnums[parent_attno - 1];
1393 if (found_whole_row)
1395 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1396 errmsg(
"cannot convert whole-row table reference"),
1397 errdetail(
"Generation expression for column \"%s\" contains a whole-row reference to table \"%s\".",
1401 atsubcmds =
lappend(atsubcmds, atsubcmd);
1415 for (ccnum = 0; ccnum < constr->
num_check; ccnum++)
1421 bool found_whole_row;
1436 if (found_whole_row)
1438 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1439 errmsg(
"cannot convert whole-row table reference"),
1440 errdetail(
"Constraint \"%s\" contains a whole-row reference to table \"%s\".",
1459 atsubcmds =
lappend(atsubcmds, atsubcmd);
1465 ConstraintRelationId,
1492 atsubcmds =
lappend(atsubcmds, atsubcmd);
1505 atcmd->
cmds = atsubcmds;
1508 result =
lcons(atcmd, result);
1517 relation->
rd_rel->relhasindex)
1519 List *parent_indexes;
1524 foreach(l, parent_indexes)
1552 atsubcmds =
lappend(atsubcmds, notnullcmd);
1564 atcmd->
cmds = atsubcmds;
1567 result =
lcons(atcmd, result);
1583 result =
lappend(result, index_stmt);
1615 ofTypename->
typeOid = ofTypeId;
1618 for (
i = 0;
i < tupdesc->
natts;
i++)
1623 if (attr->attisdropped)
1627 attr->atttypmod, attr->attcollation);
1687 elog(
ERROR,
"cache lookup failed for relation %u", source_relid);
1693 indrelid = idxrec->indrelid;
1698 elog(
ERROR,
"cache lookup failed for access method %u",
1704 Anum_pg_index_indcollation);
1713 index->relation = heapRel;
1718 index->tableSpace = NULL;
1720 index->idxcomment = NULL;
1725 index->unique = idxrec->indisunique;
1726 index->nulls_not_distinct = idxrec->indnullsnotdistinct;
1727 index->primary = idxrec->indisprimary;
1728 index->iswithoutoverlaps = (idxrec->indisprimary || idxrec->indisunique) && idxrec->indisexclusion;
1729 index->transformed =
true;
1730 index->concurrent =
false;
1731 index->if_not_exists =
false;
1732 index->reset_default_tblspc =
false;
1740 index->idxname = NULL;
1748 if (
index->primary ||
index->unique || idxrec->indisexclusion)
1758 *constraintOid = constraintId;
1763 elog(
ERROR,
"cache lookup failed for constraint %u",
1767 index->isconstraint =
true;
1768 index->deferrable = conrec->condeferrable;
1769 index->initdeferred = conrec->condeferred;
1772 if (idxrec->indisexclusion)
1778 Assert(conrec->contype == CONSTRAINT_EXCLUSION ||
1779 (
index->iswithoutoverlaps &&
1780 (conrec->contype == CONSTRAINT_PRIMARY || conrec->contype == CONSTRAINT_UNIQUE)));
1783 Anum_pg_constraint_conexclop);
1786 for (
i = 0;
i < nElems;
i++)
1798 elog(
ERROR,
"cache lookup failed for operator %u",
1815 index->isconstraint =
false;
1818 index->isconstraint =
false;
1822 Anum_pg_index_indexprs, &isnull);
1838 for (keyno = 0; keyno < idxrec->indnkeyatts; keyno++)
1857 iparam->
expr = NULL;
1863 bool found_whole_row;
1865 if (indexpr_item == NULL)
1866 elog(
ERROR,
"too few entries in indexprs list");
1868 indexpr_item =
lnext(indexprs, indexpr_item);
1877 if (found_whole_row)
1879 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1880 errmsg(
"cannot convert whole-row table reference"),
1881 errdetail(
"Index \"%s\" contains a whole-row table reference.",
1884 iparam->
name = NULL;
1885 iparam->
expr = indexkey;
1913 if (opt & INDOPTION_DESC)
1916 if ((opt & INDOPTION_NULLS_FIRST) == 0)
1921 if (opt & INDOPTION_NULLS_FIRST)
1930 for (keyno = idxrec->indnkeyatts; keyno < idxrec->indnatts; keyno++)
1947 iparam->
expr = NULL;
1951 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1952 errmsg(
"expressions are not supported in included columns")));
1961 Anum_pg_class_reloptions, &isnull);
1967 Anum_pg_index_indpred, &isnull);
1972 bool found_whole_row;
1985 if (found_whole_row)
1987 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1988 errmsg(
"cannot convert whole-row table reference"),
1989 errdetail(
"Index \"%s\" contains a whole-row table reference.",
1992 index->whereClause = pred_tree;
2030 elog(
ERROR,
"cache lookup failed for statistics object %u", source_statsid);
2035 Anum_pg_statistic_ext_stxkind);
2040 elog(
ERROR,
"stxkind is not a 1-D char array");
2044 if (enabled[
i] == STATS_EXT_NDISTINCT)
2046 else if (enabled[
i] == STATS_EXT_DEPENDENCIES)
2048 else if (enabled[
i] == STATS_EXT_MCV)
2050 else if (enabled[
i] == STATS_EXT_EXPRESSIONS)
2054 elog(
ERROR,
"unrecognized statistics kind %c", enabled[
i]);
2058 for (
i = 0;
i < statsrec->stxkeys.dim1;
i++)
2066 def_names =
lappend(def_names, selem);
2079 Anum_pg_statistic_ext_stxexprs, &isnull);
2097 def_names =
lappend(def_names, selem);
2107 stats->
exprs = def_names;
2141 elog(
ERROR,
"cache lookup failed for collation %u", collation);
2168 elog(
ERROR,
"cache lookup failed for opclass %u", opclass);
2229 if (cxt->
pkey != NULL)
2235 foreach(lc, indexlist)
2246 foreach(k, finalindexlist)
2267 if (priorindex->
idxname == NULL)
2305 if (cxt->
pkey != NULL)
2307 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
2308 errmsg(
"multiple primary keys for table \"%s\" are not allowed",
2319 index->isconstraint =
true;
2324 if (constraint->
conname != NULL)
2327 index->idxname = NULL;
2337 index->idxcomment = NULL;
2342 index->transformed =
false;
2343 index->concurrent =
false;
2344 index->if_not_exists =
false;
2355 char *index_name = constraint->
indexname;
2361 Datum indclassDatum;
2374 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2375 errmsg(
"cannot use an existing index in CREATE TABLE"),
2383 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2384 errmsg(
"index \"%s\" does not exist", index_name),
2394 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2395 errmsg(
"index \"%s\" is already associated with a constraint",
2402 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2403 errmsg(
"index \"%s\" does not belong to table \"%s\"",
2407 if (!index_form->indisvalid)
2409 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2410 errmsg(
"index \"%s\" is not valid", index_name),
2418 if (!index_form->indisunique)
2420 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2421 errmsg(
"\"%s\" is not a unique index", index_name),
2422 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2427 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2428 errmsg(
"index \"%s\" contains expressions", index_name),
2429 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2434 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2435 errmsg(
"\"%s\" is a partial index", index_name),
2436 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2444 if (!index_form->indimmediate && !constraint->
deferrable)
2446 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2447 errmsg(
"\"%s\" is a deferrable index", index_name),
2448 errdetail(
"Cannot create a non-deferrable constraint using a deferrable index."),
2460 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2461 errmsg(
"index \"%s\" is not a btree", index_name),
2467 Anum_pg_index_indclass);
2470 for (
i = 0;
i < index_form->indnatts;
i++)
2484 Assert(attnum <= heap_rel->rd_att->natts);
2491 if (i < index_form->indnkeyatts)
2505 index_rel->
rd_rel->relam);
2506 if (indclass->
values[
i] != defopclass ||
2508 attoptions != (
Datum) 0 ||
2511 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2512 errmsg(
"index \"%s\" column number %d does not have default sorting behavior", index_name,
i + 1),
2513 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2525 index->indexOid = index_oid;
2558 foreach(lc, constraint->
keys)
2567 foreach(columns, cxt->
columns)
2614 if (rel->
rd_rel->relkind != RELKIND_RELATION &&
2615 rel->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2616 rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2618 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2619 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2621 for (count = 0; count < rel->
rd_att->
natts; count++)
2625 char *inhname =
NameStr(inhattr->attname);
2627 if (inhattr->attisdropped)
2629 if (strcmp(
key, inhname) == 0)
2648 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2649 errmsg(
"column \"%s\" named in key does not exist",
key),
2653 foreach(columns,
index->indexParams)
2656 if (iparam->
name && strcmp(
key, iparam->
name) == 0)
2660 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2661 errmsg(
"column \"%s\" appears twice in primary key constraint",
2666 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2667 errmsg(
"column \"%s\" appears twice in unique constraint",
2676 iparam->
expr = NULL;
2691 notnullcmds =
lappend(notnullcmds, notnullcmd);
2704 errcode(ERRCODE_SYNTAX_ERROR),
2705 errmsg(
"constraint using WITHOUT OVERLAPS needs at least two columns"));
2708 index->accessMethod =
"gist";
2728 foreach(columns, cxt->
columns)
2761 if (rel->
rd_rel->relkind != RELKIND_RELATION &&
2762 rel->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2763 rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2765 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2766 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2768 for (count = 0; count < rel->
rd_att->
natts; count++)
2772 char *inhname =
NameStr(inhattr->attname);
2774 if (inhattr->attisdropped)
2776 if (strcmp(
key, inhname) == 0)
2796 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2797 errmsg(
"column \"%s\" named in key does not exist",
key),
2803 iparam->
expr = NULL;
2820 alterstmt->
cmds = notnullcmds;
2883 bool skipValidation,
bool isAddConstraint)
2917 if (!isAddConstraint)
2931 altercmd->
name = NULL;
2932 altercmd->
def = (
Node *) constraint;
2961 if (
stmt->transformed)
2982 if (
stmt->whereClause)
2993 foreach(l,
stmt->indexParams)
3026 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
3027 errmsg(
"index expressions and predicates can refer only to the table being indexed")));
3035 stmt->transformed =
true;
3056 if (
stmt->transformed)
3077 foreach(l,
stmt->exprs)
3098 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
3099 errmsg(
"statistics expressions can refer only to the table being referenced")));
3107 stmt->transformed =
true;
3124 List **actions,
Node **whereClause)
3139 if (rel->
rd_rel->relkind == RELKIND_MATVIEW)
3141 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3142 errmsg(
"rules on materialized views are not supported")));
3169 switch (
stmt->event)
3185 elog(
ERROR,
"unrecognized event type: %d",
3201 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3202 errmsg(
"rule WHERE condition cannot contain references to other relations")));
3229 foreach(l,
stmt->actions)
3271 *whereClause != NULL)
3273 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3274 errmsg(
"rules with WHERE conditions can only have SELECT, INSERT, UPDATE, or DELETE actions")));
3291 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3292 errmsg(
"conditional UNION/INTERSECT/EXCEPT statements are not implemented")));
3304 switch (
stmt->event)
3309 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3310 errmsg(
"ON SELECT rule cannot use OLD")));
3313 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3314 errmsg(
"ON SELECT rule cannot use NEW")));
3322 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3323 errmsg(
"ON INSERT rule cannot use OLD")));
3328 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3329 errmsg(
"ON DELETE rule cannot use NEW")));
3332 elog(
ERROR,
"unrecognized event type: %d",
3356 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3357 errmsg(
"cannot refer to OLD within WITH query")));
3363 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3364 errmsg(
"cannot refer to NEW within WITH query")));
3392 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3393 errmsg(
"conditional UNION/INTERSECT/EXCEPT statements are not implemented")));
3401 newactions =
lappend(newactions, top_subqry);
3406 *actions = newactions;
3430 const char *queryString,
3431 List **beforeStmts,
List **afterStmts)
3441 bool skipValidation =
true;
3462 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
3464 cxt.
stmtType =
"ALTER FOREIGN TABLE";
3494 foreach(lcmd,
stmt->cmds)
3511 skipValidation =
false;
3519 newcmds =
lappend(newcmds, cmd);
3532 skipValidation =
false;
3535 elog(
ERROR,
"unrecognized node type: %d",
3562 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3563 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
3581 newcmds =
lappend(newcmds, cmd);
3598 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3599 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
3607 newcmds =
lappend(newcmds, cmd);
3631 if (strcmp(def->
defname,
"generated") == 0)
3632 newdef =
lappend(newdef, def);
3634 newseqopts =
lappend(newseqopts, def);
3640 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3641 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
3653 seqstmt->
options = newseqopts;
3669 newcmds =
lappend(newcmds, cmd);
3683 newcmds =
lappend(newcmds, cmd);
3693 newcmds =
lappend(newcmds, cmd);
3702 save_alist = cxt.
alist;
3716 foreach(l, cxt.
alist)
3732 newcmd->
def = (
Node *) idxstmt;
3733 newcmds =
lappend(newcmds, newcmd);
3752 newcmds =
lappend(newcmds, newcmd);
3759 newcmds =
lappend(newcmds, newcmd);
3766 newcmds =
lappend(newcmds, newcmd);
3778 stmt->cmds = newcmds;
3780 *beforeStmts = cxt.
blist;
3800 bool saw_deferrability =
false;
3801 bool saw_initially =
false;
3804 #define SUPPORTS_ATTRS(node) \
3805 ((node) != NULL && \
3806 ((node)->contype == CONSTR_PRIMARY || \
3807 (node)->contype == CONSTR_UNIQUE || \
3808 (node)->contype == CONSTR_EXCLUSION || \
3809 (node)->contype == CONSTR_FOREIGN))
3811 foreach(clist, constraintList)
3816 elog(
ERROR,
"unrecognized node type: %d",
3823 (
errcode(ERRCODE_SYNTAX_ERROR),
3824 errmsg(
"misplaced DEFERRABLE clause"),
3826 if (saw_deferrability)
3828 (
errcode(ERRCODE_SYNTAX_ERROR),
3829 errmsg(
"multiple DEFERRABLE/NOT DEFERRABLE clauses not allowed"),
3831 saw_deferrability =
true;
3838 (
errcode(ERRCODE_SYNTAX_ERROR),
3839 errmsg(
"misplaced NOT DEFERRABLE clause"),
3841 if (saw_deferrability)
3843 (
errcode(ERRCODE_SYNTAX_ERROR),
3844 errmsg(
"multiple DEFERRABLE/NOT DEFERRABLE clauses not allowed"),
3846 saw_deferrability =
true;
3848 if (saw_initially &&
3851 (
errcode(ERRCODE_SYNTAX_ERROR),
3852 errmsg(
"constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3859 (
errcode(ERRCODE_SYNTAX_ERROR),
3860 errmsg(
"misplaced INITIALLY DEFERRED clause"),
3864 (
errcode(ERRCODE_SYNTAX_ERROR),
3865 errmsg(
"multiple INITIALLY IMMEDIATE/DEFERRED clauses not allowed"),
3867 saw_initially =
true;
3873 if (!saw_deferrability)
3877 (
errcode(ERRCODE_SYNTAX_ERROR),
3878 errmsg(
"constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3885 (
errcode(ERRCODE_SYNTAX_ERROR),
3886 errmsg(
"misplaced INITIALLY IMMEDIATE clause"),
3890 (
errcode(ERRCODE_SYNTAX_ERROR),
3891 errmsg(
"multiple INITIALLY IMMEDIATE/DEFERRED clauses not allowed"),
3893 saw_initially =
true;
3899 lastprimarycon = con;
3901 saw_deferrability =
false;
3902 saw_initially =
false;
3930 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3931 errmsg(
"collations are not supported by type %s",
3987 foreach(elements, schemaElts)
3993 case T_CreateSeqStmt:
4037 case T_CreateTrigStmt:
4051 elog(
ERROR,
"unrecognized node type: %d",
4074 if (*stmt_schema_name == NULL)
4075 *stmt_schema_name =
unconstify(
char *, context_schema);
4076 else if (strcmp(context_schema, *stmt_schema_name) != 0)
4078 (
errcode(ERRCODE_INVALID_SCHEMA_DEFINITION),
4079 errmsg(
"CREATE specifies a schema (%s) "
4080 "different from the one being created (%s)",
4081 *stmt_schema_name, context_schema)));
4096 switch (parentRel->
rd_rel->relkind)
4098 case RELKIND_PARTITIONED_TABLE:
4101 if (cmd->
bound != NULL)
4105 case RELKIND_PARTITIONED_INDEX:
4111 if (cmd->
bound != NULL)
4113 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4114 errmsg(
"\"%s\" is not a partitioned table",
4117 case RELKIND_RELATION:
4120 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4121 errmsg(
"table \"%s\" is not partitioned",
4127 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4128 errmsg(
"index \"%s\" is not partitioned",
4133 elog(
ERROR,
"\"%s\" is not a partitioned table or index",
4167 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4168 errmsg(
"a hash-partitioned table may not have a default partition")));
4184 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4185 errmsg(
"invalid bound specification for a hash partition"),
4188 if (spec->modulus <= 0)
4190 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4191 errmsg(
"modulus for hash partition must be an integer value greater than zero")));
4193 Assert(spec->remainder >= 0);
4195 if (spec->remainder >= spec->modulus)
4197 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4198 errmsg(
"remainder for hash partition must be less than modulus")));
4210 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4211 errmsg(
"invalid bound specification for a list partition"),
4215 if (
key->partattrs[0] != 0)
4217 key->partattrs[0],
false);
4229 foreach(cell, spec->listdatums)
4237 colname, coltype, coltypmod,
4263 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4264 errmsg(
"invalid bound specification for a range partition"),
4269 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4270 errmsg(
"FROM must specify exactly one value per partitioning column")));
4273 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4274 errmsg(
"TO must specify exactly one value per partitioning column")));
4288 elog(
ERROR,
"unexpected partition strategy: %d", (
int) strategy);
4341 else if (strcmp(
"minvalue",
cname) == 0)
4347 else if (strcmp(
"maxvalue",
cname) == 0)
4364 if (
key->partattrs[
i] != 0)
4366 key->partattrs[
i],
false);
4385 if (
value->constisnull)
4387 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4388 errmsg(
"cannot specify NULL in range bound")));
4397 result =
lappend(result, prd);
4425 if (kind == prd->
kind)
4436 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4437 errmsg(
"every bound following MAXVALUE must also be MAXVALUE"),
4443 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4444 errmsg(
"every bound following MINVALUE must also be MINVALUE"),
4456 const char *colName,
Oid colType,
int32 colTypmod,
4486 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4487 errmsg(
"specified value cannot be cast to type %s for column \"%s\"",
4502 elog(
ERROR,
"could not evaluate partition bound expression");
4512 ((
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)
int bms_next_member(const Bitmapset *a, int prevbit)
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_add_member(Bitmapset *a, int x)
#define TextDatumGetCString(d)
#define unconstify(underlying_type, expr)
#define InvalidSubTransactionId
#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 * SystemAttributeDefinition(AttrNumber attno)
const FormData_pg_attribute * SystemAttributeByName(const char *attname)
#define HeapTupleIsValid(tuple)
#define DEFAULT_INDEX_TYPE
void index_close(Relation relation, LOCKMODE lockmode)
Relation index_open(Oid relationId, LOCKMODE lockmode)
Oid GetDefaultOpClass(Oid type_id, Oid am_id)
char * ChooseRelationName(const char *name1, const char *name2, const char *label, Oid namespaceid, bool isconstraint)
if(TABLE==NULL||TABLE_index==NULL)
Assert(fmt[strlen(fmt) - 1] !='\n')
List * lappend(List *list, void *datum)
List * list_copy(const List *oldlist)
List * list_delete_nth_cell(List *list, int n)
void list_free(List *list)
List * list_concat(List *list1, const List *list2)
List * lcons(void *datum, List *list)
#define AccessExclusiveLock
AttrNumber get_attnum(Oid relid, const char *attname)
char * get_namespace_name(Oid nspid)
Datum get_attoptions(Oid relid, int16 attnum)
Oid get_rel_namespace(Oid relid)
Oid get_typcollation(Oid typid)
char * get_rel_name(Oid relid)
Oid get_atttype(Oid relid, AttrNumber attnum)
Oid get_relname_relid(const char *relname, Oid relnamespace)
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
Alias * makeAlias(const char *aliasname, List *colnames)
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
FromExpr * makeFromExpr(List *fromlist, Node *quals)
DefElem * makeDefElem(char *name, Node *arg, int location)
ColumnDef * makeColumnDef(const char *colname, Oid typeOid, int32 typmod, Oid collOid)
TypeName * makeTypeNameFromOid(Oid typeOid, int32 typmod)
FuncCall * makeFuncCall(List *name, List *args, CoercionForm funcformat, int location)
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 * generateClonedIndexStmt(RangeVar *heapRel, Relation source_idx, const AttrMap *attmap, Oid *constraintOid)
static void transformColumnType(CreateStmtContext *cxt, ColumnDef *column)
static void transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
List * transformCreateSchemaStmtElements(List *schemaElts, const char *schemaName)
CreateStatsStmt * transformStatsStmt(Oid relid, CreateStatsStmt *stmt, const char *queryString)
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)
List * expandTableLikeClause(RangeVar *heapRel, TableLikeClause *table_like_clause)
static void transformTableLikeClause(CreateStmtContext *cxt, TableLikeClause *table_like_clause)
static void transformExtendedStatistics(CreateStmtContext *cxt)
static void transformConstraintAttrs(CreateStmtContext *cxt, List *constraintList)
static void transformTableConstraint(CreateStmtContext *cxt, Constraint *constraint)
static List * get_opclass(Oid opclass, Oid actual_datatype)
IndexStmt * transformIndexStmt(Oid relid, IndexStmt *stmt, const char *queryString)
static List * transformPartitionRangeBounds(ParseState *pstate, List *blist, Relation parent)
static CreateStatsStmt * generateClonedExtStatsStmt(RangeVar *heapRel, Oid heapRelid, Oid source_statsid)
static void transformPartitionCmd(CreateStmtContext *cxt, PartitionCmd *cmd)
static void setSchemaName(const char *context_schema, char **stmt_schema_name)
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)
PartitionBoundSpec * transformPartitionBound(ParseState *pstate, Relation parent, PartitionBoundSpec *spec)
static void transformFKConstraints(CreateStmtContext *cxt, bool skipValidation, bool isAddConstraint)
#define SUPPORTS_ATTRS(node)
@ PARTITION_STRATEGY_HASH
@ PARTITION_STRATEGY_LIST
@ PARTITION_STRATEGY_RANGE
@ CONSTR_ATTR_NOT_DEFERRABLE
@ PARTITION_RANGE_DATUM_MAXVALUE
@ PARTITION_RANGE_DATUM_VALUE
@ PARTITION_RANGE_DATUM_MINVALUE
@ AT_AlterColumnGenericOptions
@ CREATE_TABLE_LIKE_COMMENTS
@ CREATE_TABLE_LIKE_GENERATED
@ CREATE_TABLE_LIKE_IDENTITY
@ CREATE_TABLE_LIKE_COMPRESSION
@ CREATE_TABLE_LIKE_STORAGE
@ CREATE_TABLE_LIKE_INDEXES
@ CREATE_TABLE_LIKE_DEFAULTS
@ CREATE_TABLE_LIKE_STATISTICS
@ CREATE_TABLE_LIKE_CONSTRAINTS
Query * transformStmt(ParseState *pstate, Node *parseTree)
TypeName * SystemTypeName(char *name)
List * SystemFuncName(char *name)
PartitionKey RelationGetPartitionKey(Relation rel)
static int get_partition_strategy(PartitionKey key)
static int32 get_partition_col_typmod(PartitionKey key, int col)
static int get_partition_natts(PartitionKey key)
static Oid get_partition_col_typid(PartitionKey key, int col)
static Oid get_partition_col_collation(PartitionKey key, int col)
static List * get_partition_exprs(PartitionKey key)
FormData_pg_am * Form_pg_am
FormData_pg_attribute * Form_pg_attribute
int errdetail_relkind_not_supported(char relkind)
FormData_pg_class * Form_pg_class
FormData_pg_collation * Form_pg_collation
List * RelationGetNotNullConstraints(Oid relid, bool cooked)
Oid get_relation_constraint_oid(Oid relid, const char *conname, bool missing_ok)
FormData_pg_constraint * Form_pg_constraint
void checkMembershipInCurrentExtension(const ObjectAddress *object)
Oid get_index_constraint(Oid indexId)
Oid getIdentitySequence(Oid relid, AttrNumber attnum, bool missing_ok)
FormData_pg_index * Form_pg_index
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define linitial_node(type, l)
#define lsecond_node(type, l)
#define foreach_current_index(var_or_cell)
static ListCell * list_head(const List *l)
#define list_make3(x1, x2, x3)
static void * list_nth(const List *list, int n)
static ListCell * lnext(const List *l, const ListCell *c)
#define list_make2(x1, x2)
FormData_pg_opclass * Form_pg_opclass
FormData_pg_operator * Form_pg_operator
FormData_pg_statistic_ext * Form_pg_statistic_ext
FormData_pg_type * Form_pg_type
Expr * expression_planner(Expr *expr)
static Oid DatumGetObjectId(Datum X)
static Datum ObjectIdGetDatum(Oid X)
static Pointer DatumGetPointer(Datum X)
void * stringToNode(const char *str)
static chr element(struct vars *v, const chr *startp, const chr *endp)
#define RelationGetRelid(relation)
#define RelationGetDescr(relation)
#define RelationGetRelationName(relation)
#define RelationGetNamespace(relation)
List * RelationGetIndexList(Relation relation)
List * RelationGetIndexPredicate(Relation relation)
List * RelationGetStatExtList(Relation relation)
Bitmapset * RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind attrKind)
List * RelationGetIndexExpressions(Relation relation)
@ INDEX_ATTR_BITMAP_PRIMARY_KEY
List * untransformRelOptions(Datum options)
#define InvalidRelFileNumber
Node * map_variable_attnos(Node *node, int target_varno, int sublevels_up, const AttrMap *attno_map, Oid to_rowtype, bool *found_whole_row)
Query * getInsertSelectQuery(Query *parsetree, Query ***subquery_ptr)
bool rangeTableEntry_used(Node *node, int rt_index, int sublevels_up)
char * deparse_expression(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit)
List * deparse_context_for(const char *aliasname, Oid relid)
char * quote_qualified_identifier(const char *qualifier, const char *ident)
void relation_close(Relation relation, LOCKMODE lockmode)
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Relation relation_open(Oid relationId, LOCKMODE lockmode)
CollateClause * collClause
RangeVar * identitySequence
bool reset_default_tblspc
PartitionBoundSpec * partbound
SortByNulls nulls_ordering
List * indexIncludingParams
const char * p_sourcetext
PartitionBoundSpec * bound
PartitionRangeDatumKind kind
struct IndexAmRoutine * rd_indam
struct HeapTupleData * rd_indextuple
Oid values[FLEXIBLE_ARRAY_MEMBER]
#define FirstLowInvalidHeapAttributeNumber
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_openrv(const RangeVar *relation, LOCKMODE lockmode)
void check_of_type(HeapTuple typetuple)
const char * GetCompressionMethodName(char method)
#define CompressionMethodIsValid(cm)
Node * TupleDescGetDefault(TupleDesc tupdesc, AttrNumber attnum)
#define ReleaseTupleDesc(tupdesc)
#define TupleDescAttr(tupdesc, i)
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
String * makeString(char *str)
bool contain_var_clause(Node *node)