124 Oid heapRelid,
Oid source_statsid);
133 bool isAddConstraint);
135 bool skipValidation);
137 List *constraintList);
139 static void setSchemaName(
const char *context_schema,
char **stmt_schema_name);
145 const char *colName,
Oid colType,
int32 colTypmod,
189 stmt->relation->location);
212 (
errcode(ERRCODE_DUPLICATE_TABLE),
213 errmsg(
"relation \"%s\" already exists, skipping",
214 stmt->relation->relname)));
225 if (
stmt->relation->schemaname == NULL
226 &&
stmt->relation->relpersistence != RELPERSISTENCE_TEMP)
233 cxt.
stmtType =
"CREATE FOREIGN TABLE";
261 if (
stmt->ofTypename)
266 if (
stmt->inhRelations && !
stmt->partbound)
268 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
269 errmsg(
"cannot create partitioned table as inheritance child")));
276 foreach(elements,
stmt->tableElts)
290 case T_TableLikeClause:
295 elog(
ERROR,
"unrecognized node type: %d",
307 save_alist = cxt.
alist;
374 Oid seqtypid,
List *seqoptions,
375 bool for_identity,
bool col_exists,
376 char **snamespace_p,
char **sname_p)
405 foreach(
option, seqoptions)
409 if (strcmp(defel->
defname,
"sequence_name") == 0)
454 (
errmsg_internal(
"%s will create implicit sequence \"%s\" for serial column \"%s.%s\"",
526 (
Node *) attnamelist, -1));
535 *snamespace_p = snamespace;
553 bool need_notnull =
false;
566 if (strcmp(
typname,
"smallserial") == 0 ||
567 strcmp(
typname,
"serial2") == 0)
573 else if (strcmp(
typname,
"serial") == 0 ||
574 strcmp(
typname,
"serial4") == 0)
580 else if (strcmp(
typname,
"bigserial") == 0 ||
581 strcmp(
typname,
"serial8") == 0)
595 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
596 errmsg(
"array of serial is not implemented"),
619 &snamespace, &sname);
638 castnode->
arg = (
Node *) snamenode;
658 saw_nullable =
false;
660 saw_identity =
false;
661 saw_generated =
false;
670 if ((saw_nullable && column->
is_not_null) || need_notnull)
672 (
errcode(ERRCODE_SYNTAX_ERROR),
673 errmsg(
"conflicting NULL/NOT NULL declarations for column \"%s\" of table \"%s\"",
688 (
errcode(ERRCODE_SYNTAX_ERROR),
689 errmsg(
"conflicting NULL/NOT NULL declarations for column \"%s\" of table \"%s\"",
709 need_notnull =
false;
717 (
errcode(ERRCODE_SYNTAX_ERROR),
718 errmsg(
"multiple default values specified for column \"%s\" of table \"%s\"",
734 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
735 errmsg(
"identity columns are not supported on typed tables")));
738 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
739 errmsg(
"identity columns are not supported on partitions")));
747 (
errcode(ERRCODE_SYNTAX_ERROR),
748 errmsg(
"multiple identity specifications for column \"%s\" of table \"%s\"",
769 (
errcode(ERRCODE_SYNTAX_ERROR),
770 errmsg(
"conflicting NULL/NOT NULL declarations for column \"%s\" of table \"%s\"",
780 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
781 errmsg(
"generated columns are not supported on typed tables")));
784 (
errcode(ERRCODE_SYNTAX_ERROR),
785 errmsg(
"multiple generation clauses specified for column \"%s\" of table \"%s\"",
789 column->
generated = ATTRIBUTE_GENERATED_STORED;
792 saw_generated =
true;
802 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
803 errmsg(
"primary key constraints are not supported on foreign tables"),
811 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
812 errmsg(
"unique constraints are not supported on foreign tables"),
822 elog(
ERROR,
"column exclusion constraints are not supported");
828 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
829 errmsg(
"foreign key constraints are not supported on foreign tables"),
849 elog(
ERROR,
"unrecognized constraint type: %d",
854 if (saw_default && saw_identity)
856 (
errcode(ERRCODE_SYNTAX_ERROR),
857 errmsg(
"both default and identity specified for column \"%s\" of table \"%s\"",
862 if (saw_default && saw_generated)
864 (
errcode(ERRCODE_SYNTAX_ERROR),
865 errmsg(
"both default and generation expression specified for column \"%s\" of table \"%s\"",
870 if (saw_identity && saw_generated)
872 (
errcode(ERRCODE_SYNTAX_ERROR),
873 errmsg(
"both identity and generation expression specified for column \"%s\" of table \"%s\"",
883 if (need_notnull && !(saw_nullable && column->
is_not_null))
940 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
941 errmsg(
"primary key constraints are not supported on foreign tables"),
950 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
951 errmsg(
"unique constraints are not supported on foreign tables"),
960 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
961 errmsg(
"exclusion constraints are not supported on foreign tables"),
978 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
979 errmsg(
"foreign key constraints are not supported on foreign tables"),
991 elog(
ERROR,
"invalid context for constraint type %d",
996 elog(
ERROR,
"unrecognized constraint type: %d",
1021 bool process_notnull_constraints =
false;
1029 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1030 errmsg(
"LIKE is not supported for creating foreign tables")));
1035 if (relation->
rd_rel->relkind != RELKIND_RELATION &&
1036 relation->
rd_rel->relkind != RELKIND_VIEW &&
1037 relation->
rd_rel->relkind != RELKIND_MATVIEW &&
1038 relation->
rd_rel->relkind != RELKIND_COMPOSITE_TYPE &&
1039 relation->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
1040 relation->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1042 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1043 errmsg(
"relation \"%s\" is invalid in LIKE clause",
1052 if (relation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
1076 for (parent_attno = 1; parent_attno <= tupleDesc->
natts;
1086 if (attribute->attisdropped)
1093 attribute->atttypmod, attribute->attcollation);
1100 if (attribute->attnotnull)
1101 process_notnull_constraints =
true;
1112 if (attribute->atthasdef && attribute->attgenerated &&
1114 def->
generated = attribute->attgenerated;
1119 if (attribute->attidentity &&
1135 def->
identity = attribute->attidentity;
1140 def->
storage = attribute->attstorage;
1156 attribute->attnum)) != NULL)
1182 if ((table_like_clause->
options &
1187 process_notnull_constraints)
1252 List *parent_extstats;
1257 foreach(l, parent_extstats)
1312 bool at_pushed =
false;
1323 elog(
ERROR,
"expandTableLikeClause called on untransformed LIKE clause");
1328 constr = tupleDesc->
constr;
1347 if ((table_like_clause->
options &
1351 for (parent_attno = 1; parent_attno <= tupleDesc->
natts;
1360 if (attribute->attisdropped)
1368 if (attribute->atthasdef &&
1369 (attribute->attgenerated ?
1375 bool found_whole_row;
1378 if (this_default == NULL)
1379 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
1384 atsubcmd->
num = attmap->
attnums[parent_attno - 1];
1396 if (found_whole_row)
1398 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1399 errmsg(
"cannot convert whole-row table reference"),
1400 errdetail(
"Generation expression for column \"%s\" contains a whole-row reference to table \"%s\".",
1404 atsubcmds =
lappend(atsubcmds, atsubcmd);
1418 for (ccnum = 0; ccnum < constr->
num_check; ccnum++)
1424 bool found_whole_row;
1439 if (found_whole_row)
1441 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1442 errmsg(
"cannot convert whole-row table reference"),
1443 errdetail(
"Constraint \"%s\" contains a whole-row reference to table \"%s\".",
1462 atsubcmds =
lappend(atsubcmds, atsubcmd);
1468 ConstraintRelationId,
1495 atsubcmds =
lappend(atsubcmds, atsubcmd);
1508 atcmd->
cmds = atsubcmds;
1511 result =
lcons(atcmd, result);
1520 relation->
rd_rel->relhasindex)
1522 List *parent_indexes;
1527 foreach(l, parent_indexes)
1555 atsubcmds =
lappend(atsubcmds, notnullcmd);
1567 atcmd->
cmds = atsubcmds;
1570 result =
lcons(atcmd, result);
1586 result =
lappend(result, index_stmt);
1618 ofTypename->
typeOid = ofTypeId;
1621 for (
i = 0;
i < tupdesc->
natts;
i++)
1626 if (attr->attisdropped)
1630 attr->atttypmod, attr->attcollation);
1690 elog(
ERROR,
"cache lookup failed for relation %u", source_relid);
1696 indrelid = idxrec->indrelid;
1701 elog(
ERROR,
"cache lookup failed for access method %u",
1707 Anum_pg_index_indcollation);
1716 index->relation = heapRel;
1721 index->tableSpace = NULL;
1723 index->idxcomment = NULL;
1728 index->unique = idxrec->indisunique;
1729 index->nulls_not_distinct = idxrec->indnullsnotdistinct;
1730 index->primary = idxrec->indisprimary;
1731 index->iswithoutoverlaps = (idxrec->indisprimary || idxrec->indisunique) && idxrec->indisexclusion;
1732 index->transformed =
true;
1733 index->concurrent =
false;
1734 index->if_not_exists =
false;
1735 index->reset_default_tblspc =
false;
1743 index->idxname = NULL;
1751 if (
index->primary ||
index->unique || idxrec->indisexclusion)
1761 *constraintOid = constraintId;
1766 elog(
ERROR,
"cache lookup failed for constraint %u",
1770 index->isconstraint =
true;
1771 index->deferrable = conrec->condeferrable;
1772 index->initdeferred = conrec->condeferred;
1775 if (idxrec->indisexclusion)
1781 Assert(conrec->contype == CONSTRAINT_EXCLUSION ||
1782 (
index->iswithoutoverlaps &&
1783 (conrec->contype == CONSTRAINT_PRIMARY || conrec->contype == CONSTRAINT_UNIQUE)));
1786 Anum_pg_constraint_conexclop);
1789 for (
i = 0;
i < nElems;
i++)
1801 elog(
ERROR,
"cache lookup failed for operator %u",
1818 index->isconstraint =
false;
1821 index->isconstraint =
false;
1825 Anum_pg_index_indexprs, &isnull);
1841 for (keyno = 0; keyno < idxrec->indnkeyatts; keyno++)
1860 iparam->
expr = NULL;
1866 bool found_whole_row;
1868 if (indexpr_item == NULL)
1869 elog(
ERROR,
"too few entries in indexprs list");
1871 indexpr_item =
lnext(indexprs, indexpr_item);
1880 if (found_whole_row)
1882 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1883 errmsg(
"cannot convert whole-row table reference"),
1884 errdetail(
"Index \"%s\" contains a whole-row table reference.",
1887 iparam->
name = NULL;
1888 iparam->
expr = indexkey;
1916 if (opt & INDOPTION_DESC)
1919 if ((opt & INDOPTION_NULLS_FIRST) == 0)
1924 if (opt & INDOPTION_NULLS_FIRST)
1933 for (keyno = idxrec->indnkeyatts; keyno < idxrec->indnatts; keyno++)
1950 iparam->
expr = NULL;
1954 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1955 errmsg(
"expressions are not supported in included columns")));
1964 Anum_pg_class_reloptions, &isnull);
1970 Anum_pg_index_indpred, &isnull);
1975 bool found_whole_row;
1988 if (found_whole_row)
1990 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1991 errmsg(
"cannot convert whole-row table reference"),
1992 errdetail(
"Index \"%s\" contains a whole-row table reference.",
1995 index->whereClause = pred_tree;
2033 elog(
ERROR,
"cache lookup failed for statistics object %u", source_statsid);
2038 Anum_pg_statistic_ext_stxkind);
2043 elog(
ERROR,
"stxkind is not a 1-D char array");
2047 if (enabled[
i] == STATS_EXT_NDISTINCT)
2049 else if (enabled[
i] == STATS_EXT_DEPENDENCIES)
2051 else if (enabled[
i] == STATS_EXT_MCV)
2053 else if (enabled[
i] == STATS_EXT_EXPRESSIONS)
2057 elog(
ERROR,
"unrecognized statistics kind %c", enabled[
i]);
2061 for (
i = 0;
i < statsrec->stxkeys.dim1;
i++)
2069 def_names =
lappend(def_names, selem);
2082 Anum_pg_statistic_ext_stxexprs, &isnull);
2100 def_names =
lappend(def_names, selem);
2110 stats->
exprs = def_names;
2144 elog(
ERROR,
"cache lookup failed for collation %u", collation);
2171 elog(
ERROR,
"cache lookup failed for opclass %u", opclass);
2232 if (cxt->
pkey != NULL)
2238 foreach(lc, indexlist)
2249 foreach(k, finalindexlist)
2270 if (priorindex->
idxname == NULL)
2308 if (cxt->
pkey != NULL)
2310 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
2311 errmsg(
"multiple primary keys for table \"%s\" are not allowed",
2322 index->isconstraint =
true;
2327 if (constraint->
conname != NULL)
2330 index->idxname = NULL;
2340 index->idxcomment = NULL;
2345 index->transformed =
false;
2346 index->concurrent =
false;
2347 index->if_not_exists =
false;
2358 char *index_name = constraint->
indexname;
2364 Datum indclassDatum;
2377 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2378 errmsg(
"cannot use an existing index in CREATE TABLE"),
2386 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2387 errmsg(
"index \"%s\" does not exist", index_name),
2397 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2398 errmsg(
"index \"%s\" is already associated with a constraint",
2405 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2406 errmsg(
"index \"%s\" does not belong to table \"%s\"",
2410 if (!index_form->indisvalid)
2412 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2413 errmsg(
"index \"%s\" is not valid", index_name),
2421 if (!index_form->indisunique)
2423 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2424 errmsg(
"\"%s\" is not a unique index", index_name),
2425 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2430 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2431 errmsg(
"index \"%s\" contains expressions", index_name),
2432 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2437 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2438 errmsg(
"\"%s\" is a partial index", index_name),
2439 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2447 if (!index_form->indimmediate && !constraint->
deferrable)
2449 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2450 errmsg(
"\"%s\" is a deferrable index", index_name),
2451 errdetail(
"Cannot create a non-deferrable constraint using a deferrable index."),
2463 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2464 errmsg(
"index \"%s\" is not a btree", index_name),
2470 Anum_pg_index_indclass);
2473 for (
i = 0;
i < index_form->indnatts;
i++)
2487 Assert(attnum <= heap_rel->rd_att->natts);
2494 if (i < index_form->indnkeyatts)
2508 index_rel->
rd_rel->relam);
2509 if (indclass->
values[
i] != defopclass ||
2511 attoptions != (
Datum) 0 ||
2514 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2515 errmsg(
"index \"%s\" column number %d does not have default sorting behavior", index_name,
i + 1),
2516 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2528 index->indexOid = index_oid;
2561 foreach(lc, constraint->
keys)
2570 foreach(columns, cxt->
columns)
2617 if (rel->
rd_rel->relkind != RELKIND_RELATION &&
2618 rel->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2619 rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2621 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2622 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2624 for (count = 0; count < rel->
rd_att->
natts; count++)
2628 char *inhname =
NameStr(inhattr->attname);
2630 if (inhattr->attisdropped)
2632 if (strcmp(
key, inhname) == 0)
2651 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2652 errmsg(
"column \"%s\" named in key does not exist",
key),
2656 foreach(columns,
index->indexParams)
2659 if (iparam->
name && strcmp(
key, iparam->
name) == 0)
2663 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2664 errmsg(
"column \"%s\" appears twice in primary key constraint",
2669 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2670 errmsg(
"column \"%s\" appears twice in unique constraint",
2679 iparam->
expr = NULL;
2694 notnullcmds =
lappend(notnullcmds, notnullcmd);
2707 errcode(ERRCODE_SYNTAX_ERROR),
2708 errmsg(
"constraint using WITHOUT OVERLAPS needs at least two columns"));
2711 index->accessMethod =
"gist";
2731 foreach(columns, cxt->
columns)
2764 if (rel->
rd_rel->relkind != RELKIND_RELATION &&
2765 rel->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2766 rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2768 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2769 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2771 for (count = 0; count < rel->
rd_att->
natts; count++)
2775 char *inhname =
NameStr(inhattr->attname);
2777 if (inhattr->attisdropped)
2779 if (strcmp(
key, inhname) == 0)
2799 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2800 errmsg(
"column \"%s\" named in key does not exist",
key),
2806 iparam->
expr = NULL;
2823 alterstmt->
cmds = notnullcmds;
2886 bool skipValidation,
bool isAddConstraint)
2920 if (!isAddConstraint)
2934 altercmd->
name = NULL;
2935 altercmd->
def = (
Node *) constraint;
2964 if (
stmt->transformed)
2985 if (
stmt->whereClause)
2996 foreach(l,
stmt->indexParams)
3029 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
3030 errmsg(
"index expressions and predicates can refer only to the table being indexed")));
3038 stmt->transformed =
true;
3059 if (
stmt->transformed)
3080 foreach(l,
stmt->exprs)
3101 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
3102 errmsg(
"statistics expressions can refer only to the table being referenced")));
3110 stmt->transformed =
true;
3127 List **actions,
Node **whereClause)
3142 if (rel->
rd_rel->relkind == RELKIND_MATVIEW)
3144 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3145 errmsg(
"rules on materialized views are not supported")));
3172 switch (
stmt->event)
3188 elog(
ERROR,
"unrecognized event type: %d",
3204 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3205 errmsg(
"rule WHERE condition cannot contain references to other relations")));
3232 foreach(l,
stmt->actions)
3274 *whereClause != NULL)
3276 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3277 errmsg(
"rules with WHERE conditions can only have SELECT, INSERT, UPDATE, or DELETE actions")));
3294 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3295 errmsg(
"conditional UNION/INTERSECT/EXCEPT statements are not implemented")));
3307 switch (
stmt->event)
3312 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3313 errmsg(
"ON SELECT rule cannot use OLD")));
3316 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3317 errmsg(
"ON SELECT rule cannot use NEW")));
3325 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3326 errmsg(
"ON INSERT rule cannot use OLD")));
3331 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3332 errmsg(
"ON DELETE rule cannot use NEW")));
3335 elog(
ERROR,
"unrecognized event type: %d",
3359 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3360 errmsg(
"cannot refer to OLD within WITH query")));
3366 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3367 errmsg(
"cannot refer to NEW within WITH query")));
3395 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3396 errmsg(
"conditional UNION/INTERSECT/EXCEPT statements are not implemented")));
3404 newactions =
lappend(newactions, top_subqry);
3409 *actions = newactions;
3430 if (partRel->
rd_rel->relkind != RELKIND_RELATION)
3432 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3433 errmsg(
"\"%s\" is not a table",
3436 if (!partRel->
rd_rel->relispartition)
3438 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3439 errmsg(
"\"%s\" is not a partition",
3445 errmsg(
"relation \"%s\" is not a partition of relation \"%s\"",
3466 if (parent->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
3468 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3472 foreach(listptr, partcmd->
partlist)
3508 bool isDefaultPart =
false;
3511 if (parent->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
3513 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3521 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3522 errmsg(
"partition of hash-partitioned table cannot be merged")));
3528 foreach(listptr, partcmd->
partlist)
3539 (
errcode(ERRCODE_DUPLICATE_TABLE),
3540 errmsg(
"partition with name \"%s\" is already used",
name->relname)),
3546 if (partOid == defaultPartOid)
3547 isDefaultPart =
true;
3564 partOids, partcmd->
bound,
3582 const char *queryString,
3583 List **beforeStmts,
List **afterStmts)
3593 bool skipValidation =
true;
3614 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
3616 cxt.
stmtType =
"ALTER FOREIGN TABLE";
3646 foreach(lcmd,
stmt->cmds)
3663 skipValidation =
false;
3671 newcmds =
lappend(newcmds, cmd);
3684 skipValidation =
false;
3687 elog(
ERROR,
"unrecognized node type: %d",
3714 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3715 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
3733 newcmds =
lappend(newcmds, cmd);
3750 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3751 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
3759 newcmds =
lappend(newcmds, cmd);
3783 if (strcmp(def->
defname,
"generated") == 0)
3784 newdef =
lappend(newdef, def);
3786 newseqopts =
lappend(newseqopts, def);
3792 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3793 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
3805 seqstmt->
options = newseqopts;
3821 newcmds =
lappend(newcmds, cmd);
3835 newcmds =
lappend(newcmds, cmd);
3845 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3846 errmsg(
"list of new partitions should contain at least two items")));
3852 newcmds =
lappend(newcmds, cmd);
3863 newcmds =
lappend(newcmds, cmd);
3872 save_alist = cxt.
alist;
3886 foreach(l, cxt.
alist)
3902 newcmd->
def = (
Node *) idxstmt;
3903 newcmds =
lappend(newcmds, newcmd);
3922 newcmds =
lappend(newcmds, newcmd);
3929 newcmds =
lappend(newcmds, newcmd);
3936 newcmds =
lappend(newcmds, newcmd);
3948 stmt->cmds = newcmds;
3950 *beforeStmts = cxt.
blist;
3970 bool saw_deferrability =
false;
3971 bool saw_initially =
false;
3974 #define SUPPORTS_ATTRS(node) \
3975 ((node) != NULL && \
3976 ((node)->contype == CONSTR_PRIMARY || \
3977 (node)->contype == CONSTR_UNIQUE || \
3978 (node)->contype == CONSTR_EXCLUSION || \
3979 (node)->contype == CONSTR_FOREIGN))
3981 foreach(clist, constraintList)
3986 elog(
ERROR,
"unrecognized node type: %d",
3993 (
errcode(ERRCODE_SYNTAX_ERROR),
3994 errmsg(
"misplaced DEFERRABLE clause"),
3996 if (saw_deferrability)
3998 (
errcode(ERRCODE_SYNTAX_ERROR),
3999 errmsg(
"multiple DEFERRABLE/NOT DEFERRABLE clauses not allowed"),
4001 saw_deferrability =
true;
4008 (
errcode(ERRCODE_SYNTAX_ERROR),
4009 errmsg(
"misplaced NOT DEFERRABLE clause"),
4011 if (saw_deferrability)
4013 (
errcode(ERRCODE_SYNTAX_ERROR),
4014 errmsg(
"multiple DEFERRABLE/NOT DEFERRABLE clauses not allowed"),
4016 saw_deferrability =
true;
4018 if (saw_initially &&
4021 (
errcode(ERRCODE_SYNTAX_ERROR),
4022 errmsg(
"constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
4029 (
errcode(ERRCODE_SYNTAX_ERROR),
4030 errmsg(
"misplaced INITIALLY DEFERRED clause"),
4034 (
errcode(ERRCODE_SYNTAX_ERROR),
4035 errmsg(
"multiple INITIALLY IMMEDIATE/DEFERRED clauses not allowed"),
4037 saw_initially =
true;
4043 if (!saw_deferrability)
4047 (
errcode(ERRCODE_SYNTAX_ERROR),
4048 errmsg(
"constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
4055 (
errcode(ERRCODE_SYNTAX_ERROR),
4056 errmsg(
"misplaced INITIALLY IMMEDIATE clause"),
4060 (
errcode(ERRCODE_SYNTAX_ERROR),
4061 errmsg(
"multiple INITIALLY IMMEDIATE/DEFERRED clauses not allowed"),
4063 saw_initially =
true;
4069 lastprimarycon = con;
4071 saw_deferrability =
false;
4072 saw_initially =
false;
4100 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4101 errmsg(
"collations are not supported by type %s",
4157 foreach(elements, schemaElts)
4163 case T_CreateSeqStmt:
4207 case T_CreateTrigStmt:
4221 elog(
ERROR,
"unrecognized node type: %d",
4244 if (*stmt_schema_name == NULL)
4245 *stmt_schema_name =
unconstify(
char *, context_schema);
4246 else if (strcmp(context_schema, *stmt_schema_name) != 0)
4248 (
errcode(ERRCODE_INVALID_SCHEMA_DEFINITION),
4249 errmsg(
"CREATE specifies a schema (%s) "
4250 "different from the one being created (%s)",
4251 *stmt_schema_name, context_schema)));
4266 switch (parentRel->
rd_rel->relkind)
4268 case RELKIND_PARTITIONED_TABLE:
4275 case RELKIND_PARTITIONED_INDEX:
4283 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4284 errmsg(
"\"%s\" is not a partitioned table",
4287 case RELKIND_RELATION:
4290 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4291 errmsg(
"table \"%s\" is not partitioned",
4297 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4298 errmsg(
"index \"%s\" is not partitioned",
4303 elog(
ERROR,
"\"%s\" is not a partitioned table or index",
4337 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4338 errmsg(
"a hash-partitioned table may not have a default partition")));
4354 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4355 errmsg(
"invalid bound specification for a hash partition"),
4358 if (spec->modulus <= 0)
4360 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4361 errmsg(
"modulus for hash partition must be an integer value greater than zero")));
4363 Assert(spec->remainder >= 0);
4365 if (spec->remainder >= spec->modulus)
4367 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4368 errmsg(
"remainder for hash partition must be less than modulus")));
4380 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4381 errmsg(
"invalid bound specification for a list partition"),
4385 if (
key->partattrs[0] != 0)
4387 key->partattrs[0],
false);
4399 foreach(cell, spec->listdatums)
4407 colname, coltype, coltypmod,
4433 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4434 errmsg(
"invalid bound specification for a range partition"),
4439 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4440 errmsg(
"FROM must specify exactly one value per partitioning column")));
4443 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4444 errmsg(
"TO must specify exactly one value per partitioning column")));
4458 elog(
ERROR,
"unexpected partition strategy: %d", (
int) strategy);
4511 else if (strcmp(
"minvalue",
cname) == 0)
4517 else if (strcmp(
"maxvalue",
cname) == 0)
4534 if (
key->partattrs[
i] != 0)
4536 key->partattrs[
i],
false);
4555 if (
value->constisnull)
4557 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4558 errmsg(
"cannot specify NULL in range bound")));
4567 result =
lappend(result, prd);
4595 if (kind == prd->
kind)
4606 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4607 errmsg(
"every bound following MAXVALUE must also be MAXVALUE"),
4613 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4614 errmsg(
"every bound following MINVALUE must also be MINVALUE"),
4626 const char *colName,
Oid colType,
int32 colTypmod,
4656 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4657 errmsg(
"specified value cannot be cast to type %s for column \"%s\"",
4672 elog(
ERROR,
"could not evaluate partition bound expression");
4682 ((
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 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 * 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)
List * lappend(List *list, void *datum)
List * lappend_oid(List *list, Oid 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)
#define RangeVarGetRelid(relation, lockmode, missing_ok)
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 transformPartitionCmdForSplit(CreateStmtContext *cxt, PartitionCmd *partcmd)
static void transformTableConstraint(CreateStmtContext *cxt, Constraint *constraint)
static List * get_opclass(Oid opclass, Oid actual_datatype)
static void transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd)
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 setSchemaName(const char *context_schema, char **stmt_schema_name)
static void validateInfiniteBounds(ParseState *pstate, List *blist)
static void transformPartitionCmd(CreateStmtContext *cxt, PartitionBoundSpec *bound)
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 void checkPartition(Relation rel, Oid partRelOid)
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)
void calculate_partition_bound_for_merge(Relation parent, List *partNames, List *partOids, PartitionBoundSpec *spec, ParseState *pstate)
void check_partitions_for_split(Relation parent, Oid splitPartOid, RangeVar *splitPartName, List *partlist, ParseState *pstate)
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)
PartitionDesc RelationGetPartitionDesc(Relation rel, bool omit_detached)
Oid get_default_oid_from_partdesc(PartitionDesc partdesc)
Oid get_partition_parent(Oid relid, bool even_if_detached)
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)
#define for_each_cell(cell, lst, initcell)
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
#define ERRCODE_UNDEFINED_TABLE
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
PartitionBoundSpec * bound
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)