132 bool isAddConstraint);
134 bool skipValidation);
136 List *constraintList);
138 static void setSchemaName(
const char *context_schema,
char **stmt_schema_name);
144 const char *colName,
Oid colType,
int32 colTypmod,
188 stmt->relation->location);
211 (
errcode(ERRCODE_DUPLICATE_TABLE),
212 errmsg(
"relation \"%s\" already exists, skipping",
213 stmt->relation->relname)));
224 if (
stmt->relation->schemaname == NULL
225 &&
stmt->relation->relpersistence != RELPERSISTENCE_TEMP)
232 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;
365 Oid seqtypid,
List *seqoptions,
366 bool for_identity,
bool col_exists,
367 char **snamespace_p,
char **sname_p)
396 foreach(
option, seqoptions)
400 if (strcmp(defel->
defname,
"sequence_name") == 0)
445 (
errmsg_internal(
"%s will create implicit sequence \"%s\" for serial column \"%s.%s\"",
517 (
Node *) attnamelist, -1));
526 *snamespace_p = snamespace;
556 if (strcmp(
typname,
"smallserial") == 0 ||
557 strcmp(
typname,
"serial2") == 0)
563 else if (strcmp(
typname,
"serial") == 0 ||
564 strcmp(
typname,
"serial4") == 0)
570 else if (strcmp(
typname,
"bigserial") == 0 ||
571 strcmp(
typname,
"serial8") == 0)
585 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
586 errmsg(
"array of serial is not implemented"),
609 &snamespace, &sname);
628 castnode->
arg = (
Node *) snamenode;
650 saw_nullable =
false;
652 saw_identity =
false;
653 saw_generated =
false;
664 (
errcode(ERRCODE_SYNTAX_ERROR),
665 errmsg(
"conflicting NULL/NOT NULL declarations for column \"%s\" of table \"%s\"",
676 (
errcode(ERRCODE_SYNTAX_ERROR),
677 errmsg(
"conflicting NULL/NOT NULL declarations for column \"%s\" of table \"%s\"",
688 (
errcode(ERRCODE_SYNTAX_ERROR),
689 errmsg(
"multiple default values specified for column \"%s\" of table \"%s\"",
705 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
706 errmsg(
"identity columns are not supported on typed tables")));
709 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
710 errmsg(
"identity columns are not supported on partitions")));
718 (
errcode(ERRCODE_SYNTAX_ERROR),
719 errmsg(
"multiple identity specifications for column \"%s\" of table \"%s\"",
735 (
errcode(ERRCODE_SYNTAX_ERROR),
736 errmsg(
"conflicting NULL/NOT NULL declarations for column \"%s\" of table \"%s\"",
748 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
749 errmsg(
"generated columns are not supported on typed tables")));
752 (
errcode(ERRCODE_SYNTAX_ERROR),
753 errmsg(
"multiple generation clauses specified for column \"%s\" of table \"%s\"",
757 column->
generated = ATTRIBUTE_GENERATED_STORED;
760 saw_generated =
true;
770 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
771 errmsg(
"primary key constraints are not supported on foreign tables"),
779 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
780 errmsg(
"unique constraints are not supported on foreign tables"),
790 elog(
ERROR,
"column exclusion constraints are not supported");
796 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
797 errmsg(
"foreign key constraints are not supported on foreign tables"),
817 elog(
ERROR,
"unrecognized constraint type: %d",
822 if (saw_default && saw_identity)
824 (
errcode(ERRCODE_SYNTAX_ERROR),
825 errmsg(
"both default and identity specified for column \"%s\" of table \"%s\"",
830 if (saw_default && saw_generated)
832 (
errcode(ERRCODE_SYNTAX_ERROR),
833 errmsg(
"both default and generation expression specified for column \"%s\" of table \"%s\"",
838 if (saw_identity && saw_generated)
840 (
errcode(ERRCODE_SYNTAX_ERROR),
841 errmsg(
"both identity and generation expression specified for column \"%s\" of table \"%s\"",
885 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
886 errmsg(
"primary key constraints are not supported on foreign tables"),
895 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
896 errmsg(
"unique constraints are not supported on foreign tables"),
905 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
906 errmsg(
"exclusion constraints are not supported on foreign tables"),
919 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
920 errmsg(
"foreign key constraints are not supported on foreign tables"),
933 elog(
ERROR,
"invalid context for constraint type %d",
938 elog(
ERROR,
"unrecognized constraint type: %d",
970 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
971 errmsg(
"LIKE is not supported for creating foreign tables")));
976 if (relation->
rd_rel->relkind != RELKIND_RELATION &&
977 relation->
rd_rel->relkind != RELKIND_VIEW &&
978 relation->
rd_rel->relkind != RELKIND_MATVIEW &&
979 relation->
rd_rel->relkind != RELKIND_COMPOSITE_TYPE &&
980 relation->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
981 relation->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
983 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
984 errmsg(
"relation \"%s\" is invalid in LIKE clause",
993 if (relation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
1017 for (parent_attno = 1; parent_attno <= tupleDesc->
natts;
1027 if (attribute->attisdropped)
1037 attribute->atttypmod, attribute->attcollation);
1049 if (attribute->atthasdef && attribute->attgenerated &&
1051 def->
generated = attribute->attgenerated;
1056 if (attribute->attidentity &&
1072 def->
identity = attribute->attidentity;
1077 def->
storage = attribute->attstorage;
1093 attribute->attnum)) != NULL)
1116 if (table_like_clause->
options &
1164 elog(
ERROR,
"expandTableLikeClause called on untransformed LIKE clause");
1169 constr = tupleDesc->
constr;
1188 if ((table_like_clause->
options &
1192 for (parent_attno = 1; parent_attno <= tupleDesc->
natts;
1201 if (attribute->attisdropped)
1209 if (attribute->atthasdef &&
1210 (attribute->attgenerated ?
1216 bool found_whole_row;
1219 if (this_default == NULL)
1220 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
1225 atsubcmd->
num = attmap->
attnums[parent_attno - 1];
1237 if (found_whole_row)
1239 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1240 errmsg(
"cannot convert whole-row table reference"),
1241 errdetail(
"Generation expression for column \"%s\" contains a whole-row reference to table \"%s\".",
1245 atsubcmds =
lappend(atsubcmds, atsubcmd);
1259 for (ccnum = 0; ccnum < constr->
num_check; ccnum++)
1265 bool found_whole_row;
1280 if (found_whole_row)
1282 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1283 errmsg(
"cannot convert whole-row table reference"),
1284 errdetail(
"Constraint \"%s\" contains a whole-row reference to table \"%s\".",
1303 atsubcmds =
lappend(atsubcmds, atsubcmd);
1309 ConstraintRelationId,
1335 atcmd->
cmds = atsubcmds;
1338 result =
lcons(atcmd, result);
1345 relation->
rd_rel->relhasindex)
1347 List *parent_indexes;
1352 foreach(l, parent_indexes)
1378 result =
lappend(result, index_stmt);
1389 List *parent_extstats;
1394 foreach(l, parent_extstats)
1416 result =
lappend(result, stats_stmt);
1448 ofTypename->
typeOid = ofTypeId;
1451 for (
i = 0;
i < tupdesc->
natts;
i++)
1456 if (attr->attisdropped)
1460 attr->atttypmod, attr->attcollation);
1520 elog(
ERROR,
"cache lookup failed for relation %u", source_relid);
1526 indrelid = idxrec->indrelid;
1531 elog(
ERROR,
"cache lookup failed for access method %u",
1537 Anum_pg_index_indcollation);
1546 index->relation = heapRel;
1551 index->tableSpace = NULL;
1553 index->idxcomment = NULL;
1558 index->unique = idxrec->indisunique;
1559 index->nulls_not_distinct = idxrec->indnullsnotdistinct;
1560 index->primary = idxrec->indisprimary;
1561 index->transformed =
true;
1562 index->concurrent =
false;
1563 index->if_not_exists =
false;
1564 index->reset_default_tblspc =
false;
1572 index->idxname = NULL;
1580 if (
index->primary ||
index->unique || idxrec->indisexclusion)
1590 *constraintOid = constraintId;
1595 elog(
ERROR,
"cache lookup failed for constraint %u",
1599 index->isconstraint =
true;
1600 index->deferrable = conrec->condeferrable;
1601 index->initdeferred = conrec->condeferred;
1604 if (idxrec->indisexclusion)
1610 Assert(conrec->contype == CONSTRAINT_EXCLUSION);
1613 Anum_pg_constraint_conexclop);
1616 for (
i = 0;
i < nElems;
i++)
1628 elog(
ERROR,
"cache lookup failed for operator %u",
1645 index->isconstraint =
false;
1648 index->isconstraint =
false;
1652 Anum_pg_index_indexprs, &isnull);
1668 for (keyno = 0; keyno < idxrec->indnkeyatts; keyno++)
1687 iparam->
expr = NULL;
1693 bool found_whole_row;
1695 if (indexpr_item == NULL)
1696 elog(
ERROR,
"too few entries in indexprs list");
1698 indexpr_item =
lnext(indexprs, indexpr_item);
1707 if (found_whole_row)
1709 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1710 errmsg(
"cannot convert whole-row table reference"),
1711 errdetail(
"Index \"%s\" contains a whole-row table reference.",
1714 iparam->
name = NULL;
1715 iparam->
expr = indexkey;
1743 if (opt & INDOPTION_DESC)
1746 if ((opt & INDOPTION_NULLS_FIRST) == 0)
1751 if (opt & INDOPTION_NULLS_FIRST)
1760 for (keyno = idxrec->indnkeyatts; keyno < idxrec->indnatts; keyno++)
1777 iparam->
expr = NULL;
1781 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1782 errmsg(
"expressions are not supported in included columns")));
1791 Anum_pg_class_reloptions, &isnull);
1797 Anum_pg_index_indpred, &isnull);
1802 bool found_whole_row;
1815 if (found_whole_row)
1817 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1818 errmsg(
"cannot convert whole-row table reference"),
1819 errdetail(
"Index \"%s\" contains a whole-row table reference.",
1822 index->whereClause = pred_tree;
1862 elog(
ERROR,
"cache lookup failed for statistics object %u", source_statsid);
1867 Anum_pg_statistic_ext_stxkind);
1872 elog(
ERROR,
"stxkind is not a 1-D char array");
1876 if (enabled[
i] == STATS_EXT_NDISTINCT)
1878 else if (enabled[
i] == STATS_EXT_DEPENDENCIES)
1880 else if (enabled[
i] == STATS_EXT_MCV)
1882 else if (enabled[
i] == STATS_EXT_EXPRESSIONS)
1886 elog(
ERROR,
"unrecognized statistics kind %c", enabled[
i]);
1890 for (
i = 0;
i < statsrec->stxkeys.dim1;
i++)
1898 def_names =
lappend(def_names, selem);
1911 Anum_pg_statistic_ext_stxexprs, &isnull);
1926 bool found_whole_row;
1938 def_names =
lappend(def_names, selem);
1948 stats->
exprs = def_names;
1982 elog(
ERROR,
"cache lookup failed for collation %u", collation);
2009 elog(
ERROR,
"cache lookup failed for opclass %u", opclass);
2068 if (cxt->
pkey != NULL)
2074 foreach(lc, indexlist)
2085 foreach(k, finalindexlist)
2106 if (priorindex->
idxname == NULL)
2148 if (cxt->
pkey != NULL)
2150 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
2151 errmsg(
"multiple primary keys for table \"%s\" are not allowed",
2162 index->isconstraint =
true;
2166 if (constraint->
conname != NULL)
2169 index->idxname = NULL;
2179 index->idxcomment = NULL;
2184 index->transformed =
false;
2185 index->concurrent =
false;
2186 index->if_not_exists =
false;
2197 char *index_name = constraint->
indexname;
2203 Datum indclassDatum;
2216 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2217 errmsg(
"cannot use an existing index in CREATE TABLE"),
2225 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2226 errmsg(
"index \"%s\" does not exist", index_name),
2236 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2237 errmsg(
"index \"%s\" is already associated with a constraint",
2244 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2245 errmsg(
"index \"%s\" does not belong to table \"%s\"",
2249 if (!index_form->indisvalid)
2251 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2252 errmsg(
"index \"%s\" is not valid", index_name),
2255 if (!index_form->indisunique)
2257 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2258 errmsg(
"\"%s\" is not a unique index", index_name),
2259 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2264 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2265 errmsg(
"index \"%s\" contains expressions", index_name),
2266 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2271 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2272 errmsg(
"\"%s\" is a partial index", index_name),
2273 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2281 if (!index_form->indimmediate && !constraint->
deferrable)
2283 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2284 errmsg(
"\"%s\" is a deferrable index", index_name),
2285 errdetail(
"Cannot create a non-deferrable constraint using a deferrable index."),
2297 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2298 errmsg(
"index \"%s\" is not a btree", index_name),
2304 Anum_pg_index_indclass);
2307 for (
i = 0;
i < index_form->indnatts;
i++)
2321 Assert(attnum <= heap_rel->rd_att->natts);
2328 if (i < index_form->indnkeyatts)
2342 index_rel->
rd_rel->relam);
2343 if (indclass->
values[
i] != defopclass ||
2345 attoptions != (
Datum) 0 ||
2348 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2349 errmsg(
"index \"%s\" column number %d does not have default sorting behavior", index_name,
i + 1),
2350 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2362 index->indexOid = index_oid;
2395 foreach(lc, constraint->
keys)
2399 bool forced_not_null =
false;
2405 foreach(columns, cxt->
columns)
2426 forced_not_null =
true;
2451 if (rel->
rd_rel->relkind != RELKIND_RELATION &&
2452 rel->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2453 rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2455 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2456 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2458 for (count = 0; count < rel->
rd_att->
natts; count++)
2462 char *inhname =
NameStr(inhattr->attname);
2464 if (inhattr->attisdropped)
2466 if (strcmp(
key, inhname) == 0)
2493 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2494 errmsg(
"column \"%s\" named in key does not exist",
key),
2498 foreach(columns,
index->indexParams)
2501 if (iparam->
name && strcmp(
key, iparam->
name) == 0)
2505 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2506 errmsg(
"column \"%s\" appears twice in primary key constraint",
2511 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2512 errmsg(
"column \"%s\" appears twice in unique constraint",
2521 iparam->
expr = NULL;
2540 notnullcmds =
lappend(notnullcmds, notnullcmd);
2560 foreach(columns, cxt->
columns)
2593 if (rel->
rd_rel->relkind != RELKIND_RELATION &&
2594 rel->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2595 rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2597 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2598 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2600 for (count = 0; count < rel->
rd_att->
natts; count++)
2604 char *inhname =
NameStr(inhattr->attname);
2606 if (inhattr->attisdropped)
2608 if (strcmp(
key, inhname) == 0)
2628 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2629 errmsg(
"column \"%s\" named in key does not exist",
key),
2635 iparam->
expr = NULL;
2652 alterstmt->
cmds = notnullcmds;
2702 bool skipValidation,
bool isAddConstraint)
2736 if (!isAddConstraint)
2750 altercmd->
name = NULL;
2751 altercmd->
def = (
Node *) constraint;
2780 if (
stmt->transformed)
2801 if (
stmt->whereClause)
2812 foreach(l,
stmt->indexParams)
2845 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
2846 errmsg(
"index expressions and predicates can refer only to the table being indexed")));
2854 stmt->transformed =
true;
2875 if (
stmt->transformed)
2896 foreach(l,
stmt->exprs)
2917 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
2918 errmsg(
"statistics expressions can refer only to the table being referenced")));
2926 stmt->transformed =
true;
2943 List **actions,
Node **whereClause)
2958 if (rel->
rd_rel->relkind == RELKIND_MATVIEW)
2960 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2961 errmsg(
"rules on materialized views are not supported")));
2988 switch (
stmt->event)
3004 elog(
ERROR,
"unrecognized event type: %d",
3020 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3021 errmsg(
"rule WHERE condition cannot contain references to other relations")));
3048 foreach(l,
stmt->actions)
3090 *whereClause != NULL)
3092 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3093 errmsg(
"rules with WHERE conditions can only have SELECT, INSERT, UPDATE, or DELETE actions")));
3110 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3111 errmsg(
"conditional UNION/INTERSECT/EXCEPT statements are not implemented")));
3123 switch (
stmt->event)
3128 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3129 errmsg(
"ON SELECT rule cannot use OLD")));
3132 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3133 errmsg(
"ON SELECT rule cannot use NEW")));
3141 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3142 errmsg(
"ON INSERT rule cannot use OLD")));
3147 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3148 errmsg(
"ON DELETE rule cannot use NEW")));
3151 elog(
ERROR,
"unrecognized event type: %d",
3175 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3176 errmsg(
"cannot refer to OLD within WITH query")));
3182 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3183 errmsg(
"cannot refer to NEW within WITH query")));
3211 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3212 errmsg(
"conditional UNION/INTERSECT/EXCEPT statements are not implemented")));
3220 newactions =
lappend(newactions, top_subqry);
3225 *actions = newactions;
3246 if (partRel->
rd_rel->relkind != RELKIND_RELATION)
3248 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3249 errmsg(
"\"%s\" is not a table",
3252 if (!partRel->
rd_rel->relispartition)
3254 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3255 errmsg(
"\"%s\" is not a partition",
3261 errmsg(
"relation \"%s\" is not a partition of relation \"%s\"",
3287 if (parent->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
3289 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3293 foreach(listptr, partcmd->
partlist)
3329 bool isDefaultPart =
false;
3332 if (parent->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
3334 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3342 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3343 errmsg(
"partition of hash-partitioned table cannot be merged")));
3349 foreach(listptr, partcmd->
partlist)
3360 (
errcode(ERRCODE_DUPLICATE_TABLE),
3361 errmsg(
"partition with name \"%s\" is already used",
name->relname)),
3367 if (partOid == defaultPartOid)
3368 isDefaultPart =
true;
3385 partOids, partcmd->
bound,
3403 const char *queryString,
3404 List **beforeStmts,
List **afterStmts)
3414 bool skipValidation =
true;
3435 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
3437 cxt.
stmtType =
"ALTER FOREIGN TABLE";
3465 foreach(lcmd,
stmt->cmds)
3482 skipValidation =
false;
3490 newcmds =
lappend(newcmds, cmd);
3503 skipValidation =
false;
3506 elog(
ERROR,
"unrecognized node type: %d",
3537 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3538 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
3560 newcmds =
lappend(newcmds, cmd);
3577 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3578 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
3586 newcmds =
lappend(newcmds, cmd);
3610 if (strcmp(def->
defname,
"generated") == 0)
3611 newdef =
lappend(newdef, def);
3613 newseqopts =
lappend(newseqopts, def);
3619 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3620 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
3632 seqstmt->
options = newseqopts;
3648 newcmds =
lappend(newcmds, cmd);
3662 newcmds =
lappend(newcmds, cmd);
3672 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3673 errmsg(
"list of new partitions should contain at least two items")));
3679 newcmds =
lappend(newcmds, cmd);
3690 newcmds =
lappend(newcmds, cmd);
3699 save_alist = cxt.
alist;
3713 foreach(l, cxt.
alist)
3729 newcmd->
def = (
Node *) idxstmt;
3730 newcmds =
lappend(newcmds, newcmd);
3749 newcmds =
lappend(newcmds, newcmd);
3756 newcmds =
lappend(newcmds, newcmd);
3765 stmt->cmds = newcmds;
3767 *beforeStmts = cxt.
blist;
3787 bool saw_deferrability =
false;
3788 bool saw_initially =
false;
3791 #define SUPPORTS_ATTRS(node) \
3792 ((node) != NULL && \
3793 ((node)->contype == CONSTR_PRIMARY || \
3794 (node)->contype == CONSTR_UNIQUE || \
3795 (node)->contype == CONSTR_EXCLUSION || \
3796 (node)->contype == CONSTR_FOREIGN))
3798 foreach(clist, constraintList)
3803 elog(
ERROR,
"unrecognized node type: %d",
3810 (
errcode(ERRCODE_SYNTAX_ERROR),
3811 errmsg(
"misplaced DEFERRABLE clause"),
3813 if (saw_deferrability)
3815 (
errcode(ERRCODE_SYNTAX_ERROR),
3816 errmsg(
"multiple DEFERRABLE/NOT DEFERRABLE clauses not allowed"),
3818 saw_deferrability =
true;
3825 (
errcode(ERRCODE_SYNTAX_ERROR),
3826 errmsg(
"misplaced NOT DEFERRABLE clause"),
3828 if (saw_deferrability)
3830 (
errcode(ERRCODE_SYNTAX_ERROR),
3831 errmsg(
"multiple DEFERRABLE/NOT DEFERRABLE clauses not allowed"),
3833 saw_deferrability =
true;
3835 if (saw_initially &&
3838 (
errcode(ERRCODE_SYNTAX_ERROR),
3839 errmsg(
"constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3846 (
errcode(ERRCODE_SYNTAX_ERROR),
3847 errmsg(
"misplaced INITIALLY DEFERRED clause"),
3851 (
errcode(ERRCODE_SYNTAX_ERROR),
3852 errmsg(
"multiple INITIALLY IMMEDIATE/DEFERRED clauses not allowed"),
3854 saw_initially =
true;
3860 if (!saw_deferrability)
3864 (
errcode(ERRCODE_SYNTAX_ERROR),
3865 errmsg(
"constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3872 (
errcode(ERRCODE_SYNTAX_ERROR),
3873 errmsg(
"misplaced INITIALLY IMMEDIATE clause"),
3877 (
errcode(ERRCODE_SYNTAX_ERROR),
3878 errmsg(
"multiple INITIALLY IMMEDIATE/DEFERRED clauses not allowed"),
3880 saw_initially =
true;
3886 lastprimarycon = con;
3888 saw_deferrability =
false;
3889 saw_initially =
false;
3917 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3918 errmsg(
"collations are not supported by type %s",
3974 foreach(elements, schemaElts)
3980 case T_CreateSeqStmt:
4024 case T_CreateTrigStmt:
4038 elog(
ERROR,
"unrecognized node type: %d",
4061 if (*stmt_schema_name == NULL)
4062 *stmt_schema_name =
unconstify(
char *, context_schema);
4063 else if (strcmp(context_schema, *stmt_schema_name) != 0)
4065 (
errcode(ERRCODE_INVALID_SCHEMA_DEFINITION),
4066 errmsg(
"CREATE specifies a schema (%s) "
4067 "different from the one being created (%s)",
4068 *stmt_schema_name, context_schema)));
4083 switch (parentRel->
rd_rel->relkind)
4085 case RELKIND_PARTITIONED_TABLE:
4092 case RELKIND_PARTITIONED_INDEX:
4100 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4101 errmsg(
"\"%s\" is not a partitioned table",
4104 case RELKIND_RELATION:
4107 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4108 errmsg(
"table \"%s\" is not partitioned",
4114 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4115 errmsg(
"index \"%s\" is not partitioned",
4120 elog(
ERROR,
"\"%s\" is not a partitioned table or index",
4154 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4155 errmsg(
"a hash-partitioned table may not have a default partition")));
4171 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4172 errmsg(
"invalid bound specification for a hash partition"),
4175 if (spec->modulus <= 0)
4177 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4178 errmsg(
"modulus for hash partition must be an integer value greater than zero")));
4180 Assert(spec->remainder >= 0);
4182 if (spec->remainder >= spec->modulus)
4184 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4185 errmsg(
"remainder for hash partition must be less than modulus")));
4197 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4198 errmsg(
"invalid bound specification for a list partition"),
4202 if (
key->partattrs[0] != 0)
4204 key->partattrs[0],
false);
4216 foreach(cell, spec->listdatums)
4224 colname, coltype, coltypmod,
4250 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4251 errmsg(
"invalid bound specification for a range partition"),
4256 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4257 errmsg(
"FROM must specify exactly one value per partitioning column")));
4260 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4261 errmsg(
"TO must specify exactly one value per partitioning column")));
4275 elog(
ERROR,
"unexpected partition strategy: %d", (
int) strategy);
4328 else if (strcmp(
"minvalue",
cname) == 0)
4334 else if (strcmp(
"maxvalue",
cname) == 0)
4351 if (
key->partattrs[
i] != 0)
4353 key->partattrs[
i],
false);
4372 if (
value->constisnull)
4374 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4375 errmsg(
"cannot specify NULL in range bound")));
4384 result =
lappend(result, prd);
4412 if (kind == prd->
kind)
4423 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4424 errmsg(
"every bound following MAXVALUE must also be MAXVALUE"),
4430 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4431 errmsg(
"every bound following MINVALUE must also be MINVALUE"),
4443 const char *colName,
Oid colType,
int32 colTypmod,
4473 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4474 errmsg(
"specified value cannot be cast to type %s for column \"%s\"",
4489 elog(
ERROR,
"could not evaluate partition bound expression");
4499 ((
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)
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
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 * 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 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 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)
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)
#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
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 getIdentitySequence(Relation rel, AttrNumber attnum, bool missing_ok)
Oid get_index_constraint(Oid indexId)
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 RelationGetForm(relation)
#define RelationGetRelid(relation)
#define RelationGetDescr(relation)
#define RelationGetRelationName(relation)
#define RelationGetNamespace(relation)
List * RelationGetIndexList(Relation relation)
List * RelationGetIndexPredicate(Relation relation)
List * RelationGetStatExtList(Relation relation)
List * RelationGetIndexExpressions(Relation relation)
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]
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)