129 bool isAddConstraint);
131 bool skipValidation);
133 List *constraintList);
135 static void setSchemaName(
const char *context_schema,
char **stmt_schema_name);
141 const char *colName,
Oid colType,
int32 colTypmod,
185 stmt->relation->location);
208 (
errcode(ERRCODE_DUPLICATE_TABLE),
209 errmsg(
"relation \"%s\" already exists, skipping",
210 stmt->relation->relname)));
221 if (
stmt->relation->schemaname == NULL
222 &&
stmt->relation->relpersistence != RELPERSISTENCE_TEMP)
229 cxt.
stmtType =
"CREATE FOREIGN TABLE";
255 if (
stmt->ofTypename)
260 if (
stmt->inhRelations && !
stmt->partbound)
262 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
263 errmsg(
"cannot create partitioned table as inheritance child")));
270 foreach(elements,
stmt->tableElts)
284 case T_TableLikeClause:
289 elog(
ERROR,
"unrecognized node type: %d",
301 save_alist = cxt.
alist;
362 Oid seqtypid,
List *seqoptions,
363 bool for_identity,
bool col_exists,
364 char **snamespace_p,
char **sname_p)
385 foreach(
option, seqoptions)
389 if (strcmp(defel->
defname,
"sequence_name") == 0)
396 else if (strcmp(defel->
defname,
"logged") == 0 ||
397 strcmp(defel->
defname,
"unlogged") == 0)
455 (
errmsg_internal(
"%s will create implicit sequence \"%s\" for serial column \"%s.%s\"",
472 if (seqpersistence == RELPERSISTENCE_TEMP)
474 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
475 errmsg(
"cannot set logged status of a temporary sequence"),
477 else if (strcmp(loggedEl->
defname,
"logged") == 0)
478 seqpersistence = RELPERSISTENCE_PERMANENT;
480 seqpersistence = RELPERSISTENCE_UNLOGGED;
542 (
Node *) attnamelist, -1));
551 *snamespace_p = snamespace;
581 if (strcmp(
typname,
"smallserial") == 0 ||
582 strcmp(
typname,
"serial2") == 0)
588 else if (strcmp(
typname,
"serial") == 0 ||
589 strcmp(
typname,
"serial4") == 0)
595 else if (strcmp(
typname,
"bigserial") == 0 ||
596 strcmp(
typname,
"serial8") == 0)
610 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
611 errmsg(
"array of serial is not implemented"),
634 &snamespace, &sname);
653 castnode->
arg = (
Node *) snamenode;
675 saw_nullable =
false;
677 saw_identity =
false;
678 saw_generated =
false;
689 (
errcode(ERRCODE_SYNTAX_ERROR),
690 errmsg(
"conflicting NULL/NOT NULL declarations for column \"%s\" of table \"%s\"",
701 (
errcode(ERRCODE_SYNTAX_ERROR),
702 errmsg(
"conflicting NULL/NOT NULL declarations for column \"%s\" of table \"%s\"",
713 (
errcode(ERRCODE_SYNTAX_ERROR),
714 errmsg(
"multiple default values specified for column \"%s\" of table \"%s\"",
730 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
731 errmsg(
"identity columns are not supported on typed tables")));
734 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
735 errmsg(
"identity columns are not supported on partitions")));
743 (
errcode(ERRCODE_SYNTAX_ERROR),
744 errmsg(
"multiple identity specifications for column \"%s\" of table \"%s\"",
760 (
errcode(ERRCODE_SYNTAX_ERROR),
761 errmsg(
"conflicting NULL/NOT NULL declarations for column \"%s\" of table \"%s\"",
773 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
774 errmsg(
"generated columns are not supported on typed tables")));
777 (
errcode(ERRCODE_SYNTAX_ERROR),
778 errmsg(
"multiple generation clauses specified for column \"%s\" of table \"%s\"",
782 column->
generated = ATTRIBUTE_GENERATED_STORED;
785 saw_generated =
true;
795 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
796 errmsg(
"primary key constraints are not supported on foreign tables"),
804 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
805 errmsg(
"unique constraints are not supported on foreign tables"),
815 elog(
ERROR,
"column exclusion constraints are not supported");
821 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
822 errmsg(
"foreign key constraints are not supported on foreign tables"),
842 elog(
ERROR,
"unrecognized constraint type: %d",
847 if (saw_default && saw_identity)
849 (
errcode(ERRCODE_SYNTAX_ERROR),
850 errmsg(
"both default and identity specified for column \"%s\" of table \"%s\"",
855 if (saw_default && saw_generated)
857 (
errcode(ERRCODE_SYNTAX_ERROR),
858 errmsg(
"both default and generation expression specified for column \"%s\" of table \"%s\"",
863 if (saw_identity && saw_generated)
865 (
errcode(ERRCODE_SYNTAX_ERROR),
866 errmsg(
"both identity and generation expression specified for column \"%s\" of table \"%s\"",
910 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
911 errmsg(
"primary key constraints are not supported on foreign tables"),
920 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
921 errmsg(
"unique constraints are not supported on foreign tables"),
930 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
931 errmsg(
"exclusion constraints are not supported on foreign tables"),
944 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
945 errmsg(
"foreign key constraints are not supported on foreign tables"),
958 elog(
ERROR,
"invalid context for constraint type %d",
963 elog(
ERROR,
"unrecognized constraint type: %d",
995 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
996 errmsg(
"LIKE is not supported for creating foreign tables")));
1001 if (relation->
rd_rel->relkind != RELKIND_RELATION &&
1002 relation->
rd_rel->relkind != RELKIND_VIEW &&
1003 relation->
rd_rel->relkind != RELKIND_MATVIEW &&
1004 relation->
rd_rel->relkind != RELKIND_COMPOSITE_TYPE &&
1005 relation->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
1006 relation->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1008 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1009 errmsg(
"relation \"%s\" is invalid in LIKE clause",
1018 if (relation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
1042 for (parent_attno = 1; parent_attno <= tupleDesc->
natts;
1052 if (attribute->attisdropped)
1062 attribute->atttypmod, attribute->attcollation);
1074 if (attribute->atthasdef && attribute->attgenerated &&
1076 def->
generated = attribute->attgenerated;
1081 if (attribute->attidentity &&
1097 def->
identity = attribute->attidentity;
1102 def->
storage = attribute->attstorage;
1118 attribute->attnum)) != NULL)
1141 if (table_like_clause->
options &
1189 elog(
ERROR,
"expandTableLikeClause called on untransformed LIKE clause");
1194 constr = tupleDesc->
constr;
1213 if ((table_like_clause->
options &
1217 for (parent_attno = 1; parent_attno <= tupleDesc->
natts;
1226 if (attribute->attisdropped)
1234 if (attribute->atthasdef &&
1235 (attribute->attgenerated ?
1241 bool found_whole_row;
1244 if (this_default == NULL)
1245 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
1250 atsubcmd->
num = attmap->
attnums[parent_attno - 1];
1262 if (found_whole_row)
1264 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1265 errmsg(
"cannot convert whole-row table reference"),
1266 errdetail(
"Generation expression for column \"%s\" contains a whole-row reference to table \"%s\".",
1270 atsubcmds =
lappend(atsubcmds, atsubcmd);
1284 for (ccnum = 0; ccnum < constr->
num_check; ccnum++)
1290 bool found_whole_row;
1305 if (found_whole_row)
1307 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1308 errmsg(
"cannot convert whole-row table reference"),
1309 errdetail(
"Constraint \"%s\" contains a whole-row reference to table \"%s\".",
1328 atsubcmds =
lappend(atsubcmds, atsubcmd);
1334 ConstraintRelationId,
1360 atcmd->
cmds = atsubcmds;
1363 result =
lcons(atcmd, result);
1370 relation->
rd_rel->relhasindex)
1372 List *parent_indexes;
1377 foreach(l, parent_indexes)
1403 result =
lappend(result, index_stmt);
1414 List *parent_extstats;
1419 foreach(l, parent_extstats)
1441 result =
lappend(result, stats_stmt);
1473 ofTypename->
typeOid = ofTypeId;
1476 for (
i = 0;
i < tupdesc->
natts;
i++)
1481 if (attr->attisdropped)
1485 attr->atttypmod, attr->attcollation);
1545 elog(
ERROR,
"cache lookup failed for relation %u", source_relid);
1551 indrelid = idxrec->indrelid;
1556 elog(
ERROR,
"cache lookup failed for access method %u",
1562 Anum_pg_index_indcollation);
1571 index->relation = heapRel;
1576 index->tableSpace = NULL;
1578 index->idxcomment = NULL;
1583 index->unique = idxrec->indisunique;
1584 index->nulls_not_distinct = idxrec->indnullsnotdistinct;
1585 index->primary = idxrec->indisprimary;
1586 index->iswithoutoverlaps = (idxrec->indisprimary || idxrec->indisunique) && idxrec->indisexclusion;
1587 index->transformed =
true;
1588 index->concurrent =
false;
1589 index->if_not_exists =
false;
1590 index->reset_default_tblspc =
false;
1598 index->idxname = NULL;
1606 if (
index->primary ||
index->unique || idxrec->indisexclusion)
1616 *constraintOid = constraintId;
1621 elog(
ERROR,
"cache lookup failed for constraint %u",
1625 index->isconstraint =
true;
1626 index->deferrable = conrec->condeferrable;
1627 index->initdeferred = conrec->condeferred;
1630 if (idxrec->indisexclusion)
1636 Assert(conrec->contype == CONSTRAINT_EXCLUSION ||
1637 (
index->iswithoutoverlaps &&
1638 (conrec->contype == CONSTRAINT_PRIMARY || conrec->contype == CONSTRAINT_UNIQUE)));
1641 Anum_pg_constraint_conexclop);
1644 for (
i = 0;
i < nElems;
i++)
1656 elog(
ERROR,
"cache lookup failed for operator %u",
1673 index->isconstraint =
false;
1676 index->isconstraint =
false;
1680 Anum_pg_index_indexprs, &isnull);
1696 for (keyno = 0; keyno < idxrec->indnkeyatts; keyno++)
1715 iparam->
expr = NULL;
1721 bool found_whole_row;
1723 if (indexpr_item == NULL)
1724 elog(
ERROR,
"too few entries in indexprs list");
1726 indexpr_item =
lnext(indexprs, indexpr_item);
1735 if (found_whole_row)
1737 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1738 errmsg(
"cannot convert whole-row table reference"),
1739 errdetail(
"Index \"%s\" contains a whole-row table reference.",
1742 iparam->
name = NULL;
1743 iparam->
expr = indexkey;
1771 if (opt & INDOPTION_DESC)
1774 if ((opt & INDOPTION_NULLS_FIRST) == 0)
1779 if (opt & INDOPTION_NULLS_FIRST)
1788 for (keyno = idxrec->indnkeyatts; keyno < idxrec->indnatts; keyno++)
1805 iparam->
expr = NULL;
1809 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1810 errmsg(
"expressions are not supported in included columns")));
1819 Anum_pg_class_reloptions, &isnull);
1825 Anum_pg_index_indpred, &isnull);
1830 bool found_whole_row;
1843 if (found_whole_row)
1845 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1846 errmsg(
"cannot convert whole-row table reference"),
1847 errdetail(
"Index \"%s\" contains a whole-row table reference.",
1850 index->whereClause = pred_tree;
1890 elog(
ERROR,
"cache lookup failed for statistics object %u", source_statsid);
1895 Anum_pg_statistic_ext_stxkind);
1900 elog(
ERROR,
"stxkind is not a 1-D char array");
1904 if (enabled[
i] == STATS_EXT_NDISTINCT)
1906 else if (enabled[
i] == STATS_EXT_DEPENDENCIES)
1908 else if (enabled[
i] == STATS_EXT_MCV)
1910 else if (enabled[
i] == STATS_EXT_EXPRESSIONS)
1914 elog(
ERROR,
"unrecognized statistics kind %c", enabled[
i]);
1918 for (
i = 0;
i < statsrec->stxkeys.dim1;
i++)
1926 def_names =
lappend(def_names, selem);
1939 Anum_pg_statistic_ext_stxexprs, &isnull);
1954 bool found_whole_row;
1966 def_names =
lappend(def_names, selem);
1976 stats->
exprs = def_names;
2010 elog(
ERROR,
"cache lookup failed for collation %u", collation);
2037 elog(
ERROR,
"cache lookup failed for opclass %u", opclass);
2096 if (cxt->
pkey != NULL)
2102 foreach(lc, indexlist)
2113 foreach(k, finalindexlist)
2134 if (priorindex->
idxname == NULL)
2176 if (cxt->
pkey != NULL)
2178 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
2179 errmsg(
"multiple primary keys for table \"%s\" are not allowed",
2190 index->isconstraint =
true;
2195 if (constraint->
conname != NULL)
2198 index->idxname = NULL;
2208 index->idxcomment = NULL;
2213 index->transformed =
false;
2214 index->concurrent =
false;
2215 index->if_not_exists =
false;
2226 char *index_name = constraint->
indexname;
2232 Datum indclassDatum;
2245 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2246 errmsg(
"cannot use an existing index in CREATE TABLE"),
2254 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2255 errmsg(
"index \"%s\" does not exist", index_name),
2265 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2266 errmsg(
"index \"%s\" is already associated with a constraint",
2273 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2274 errmsg(
"index \"%s\" does not belong to table \"%s\"",
2278 if (!index_form->indisvalid)
2280 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2281 errmsg(
"index \"%s\" is not valid", index_name),
2289 if (!index_form->indisunique)
2291 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2292 errmsg(
"\"%s\" is not a unique index", index_name),
2293 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2298 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2299 errmsg(
"index \"%s\" contains expressions", index_name),
2300 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2305 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2306 errmsg(
"\"%s\" is a partial index", index_name),
2307 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2315 if (!index_form->indimmediate && !constraint->
deferrable)
2317 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2318 errmsg(
"\"%s\" is a deferrable index", index_name),
2319 errdetail(
"Cannot create a non-deferrable constraint using a deferrable index."),
2331 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2332 errmsg(
"index \"%s\" is not a btree", index_name),
2338 Anum_pg_index_indclass);
2341 for (
i = 0;
i < index_form->indnatts;
i++)
2355 Assert(attnum <= heap_rel->rd_att->natts);
2362 if (i < index_form->indnkeyatts)
2376 index_rel->
rd_rel->relam);
2377 if (indclass->
values[
i] != defopclass ||
2379 attoptions != (
Datum) 0 ||
2382 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2383 errmsg(
"index \"%s\" column number %d does not have default sorting behavior", index_name,
i + 1),
2384 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2396 index->indexOid = index_oid;
2430 foreach(lc, constraint->
keys)
2434 bool forced_not_null =
false;
2441 foreach(columns, cxt->
columns)
2465 forced_not_null =
true;
2490 if (rel->
rd_rel->relkind != RELKIND_RELATION &&
2491 rel->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2492 rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2494 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2495 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2497 for (count = 0; count < rel->
rd_att->
natts; count++)
2501 char *inhname =
NameStr(inhattr->attname);
2503 if (inhattr->attisdropped)
2505 if (strcmp(
key, inhname) == 0)
2508 typid = inhattr->atttypid;
2533 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2534 errmsg(
"column \"%s\" named in key does not exist",
key),
2538 foreach(columns,
index->indexParams)
2541 if (iparam->
name && strcmp(
key, iparam->
name) == 0)
2545 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2546 errmsg(
"column \"%s\" appears twice in primary key constraint",
2551 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2552 errmsg(
"column \"%s\" appears twice in unique constraint",
2577 if (attr->attisdropped)
2584 typid = attr->atttypid;
2596 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2597 errmsg(
"column \"%s\" in WITHOUT OVERLAPS is not a range or multirange type",
key),
2605 iparam->
expr = NULL;
2624 notnullcmds =
lappend(notnullcmds, notnullcmd);
2637 errcode(ERRCODE_SYNTAX_ERROR),
2638 errmsg(
"constraint using WITHOUT OVERLAPS needs at least two columns"));
2641 index->accessMethod =
"gist";
2661 foreach(columns, cxt->
columns)
2694 if (rel->
rd_rel->relkind != RELKIND_RELATION &&
2695 rel->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2696 rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2698 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2699 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2701 for (count = 0; count < rel->
rd_att->
natts; count++)
2705 char *inhname =
NameStr(inhattr->attname);
2707 if (inhattr->attisdropped)
2709 if (strcmp(
key, inhname) == 0)
2729 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2730 errmsg(
"column \"%s\" named in key does not exist",
key),
2736 iparam->
expr = NULL;
2753 alterstmt->
cmds = notnullcmds;
2803 bool skipValidation,
bool isAddConstraint)
2837 if (!isAddConstraint)
2851 altercmd->
name = NULL;
2852 altercmd->
def = (
Node *) constraint;
2881 if (
stmt->transformed)
2902 if (
stmt->whereClause)
2913 foreach(l,
stmt->indexParams)
2946 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
2947 errmsg(
"index expressions and predicates can refer only to the table being indexed")));
2955 stmt->transformed =
true;
2976 if (
stmt->transformed)
2997 foreach(l,
stmt->exprs)
3018 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
3019 errmsg(
"statistics expressions can refer only to the table being referenced")));
3027 stmt->transformed =
true;
3044 List **actions,
Node **whereClause)
3059 if (rel->
rd_rel->relkind == RELKIND_MATVIEW)
3061 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3062 errmsg(
"rules on materialized views are not supported")));
3089 switch (
stmt->event)
3105 elog(
ERROR,
"unrecognized event type: %d",
3121 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3122 errmsg(
"rule WHERE condition cannot contain references to other relations")));
3149 foreach(l,
stmt->actions)
3191 *whereClause != NULL)
3193 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3194 errmsg(
"rules with WHERE conditions can only have SELECT, INSERT, UPDATE, or DELETE actions")));
3211 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3212 errmsg(
"conditional UNION/INTERSECT/EXCEPT statements are not implemented")));
3224 switch (
stmt->event)
3229 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3230 errmsg(
"ON SELECT rule cannot use OLD")));
3233 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3234 errmsg(
"ON SELECT rule cannot use NEW")));
3242 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3243 errmsg(
"ON INSERT rule cannot use OLD")));
3248 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3249 errmsg(
"ON DELETE rule cannot use NEW")));
3252 elog(
ERROR,
"unrecognized event type: %d",
3276 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3277 errmsg(
"cannot refer to OLD within WITH query")));
3283 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3284 errmsg(
"cannot refer to NEW within WITH query")));
3312 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3313 errmsg(
"conditional UNION/INTERSECT/EXCEPT statements are not implemented")));
3321 newactions =
lappend(newactions, top_subqry);
3326 *actions = newactions;
3350 const char *queryString,
3351 List **beforeStmts,
List **afterStmts)
3361 bool skipValidation =
true;
3382 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
3384 cxt.
stmtType =
"ALTER FOREIGN TABLE";
3412 foreach(lcmd,
stmt->cmds)
3429 skipValidation =
false;
3437 newcmds =
lappend(newcmds, cmd);
3450 skipValidation =
false;
3453 elog(
ERROR,
"unrecognized node type: %d",
3484 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3485 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
3507 newcmds =
lappend(newcmds, cmd);
3524 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3525 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
3533 newcmds =
lappend(newcmds, cmd);
3557 if (strcmp(def->
defname,
"generated") == 0)
3558 newdef =
lappend(newdef, def);
3560 newseqopts =
lappend(newseqopts, def);
3566 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3567 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
3579 seqstmt->
options = newseqopts;
3595 newcmds =
lappend(newcmds, cmd);
3609 newcmds =
lappend(newcmds, cmd);
3619 newcmds =
lappend(newcmds, cmd);
3628 save_alist = cxt.
alist;
3642 foreach(l, cxt.
alist)
3658 newcmd->
def = (
Node *) idxstmt;
3659 newcmds =
lappend(newcmds, newcmd);
3678 newcmds =
lappend(newcmds, newcmd);
3685 newcmds =
lappend(newcmds, newcmd);
3694 stmt->cmds = newcmds;
3696 *beforeStmts = cxt.
blist;
3716 bool saw_deferrability =
false;
3717 bool saw_initially =
false;
3720 #define SUPPORTS_ATTRS(node) \
3721 ((node) != NULL && \
3722 ((node)->contype == CONSTR_PRIMARY || \
3723 (node)->contype == CONSTR_UNIQUE || \
3724 (node)->contype == CONSTR_EXCLUSION || \
3725 (node)->contype == CONSTR_FOREIGN))
3727 foreach(clist, constraintList)
3732 elog(
ERROR,
"unrecognized node type: %d",
3739 (
errcode(ERRCODE_SYNTAX_ERROR),
3740 errmsg(
"misplaced DEFERRABLE clause"),
3742 if (saw_deferrability)
3744 (
errcode(ERRCODE_SYNTAX_ERROR),
3745 errmsg(
"multiple DEFERRABLE/NOT DEFERRABLE clauses not allowed"),
3747 saw_deferrability =
true;
3754 (
errcode(ERRCODE_SYNTAX_ERROR),
3755 errmsg(
"misplaced NOT DEFERRABLE clause"),
3757 if (saw_deferrability)
3759 (
errcode(ERRCODE_SYNTAX_ERROR),
3760 errmsg(
"multiple DEFERRABLE/NOT DEFERRABLE clauses not allowed"),
3762 saw_deferrability =
true;
3764 if (saw_initially &&
3767 (
errcode(ERRCODE_SYNTAX_ERROR),
3768 errmsg(
"constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3775 (
errcode(ERRCODE_SYNTAX_ERROR),
3776 errmsg(
"misplaced INITIALLY DEFERRED clause"),
3780 (
errcode(ERRCODE_SYNTAX_ERROR),
3781 errmsg(
"multiple INITIALLY IMMEDIATE/DEFERRED clauses not allowed"),
3783 saw_initially =
true;
3789 if (!saw_deferrability)
3793 (
errcode(ERRCODE_SYNTAX_ERROR),
3794 errmsg(
"constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3801 (
errcode(ERRCODE_SYNTAX_ERROR),
3802 errmsg(
"misplaced INITIALLY IMMEDIATE clause"),
3806 (
errcode(ERRCODE_SYNTAX_ERROR),
3807 errmsg(
"multiple INITIALLY IMMEDIATE/DEFERRED clauses not allowed"),
3809 saw_initially =
true;
3815 lastprimarycon = con;
3817 saw_deferrability =
false;
3818 saw_initially =
false;
3846 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3847 errmsg(
"collations are not supported by type %s",
3903 foreach(elements, schemaElts)
3909 case T_CreateSeqStmt:
3953 case T_CreateTrigStmt:
3967 elog(
ERROR,
"unrecognized node type: %d",
3990 if (*stmt_schema_name == NULL)
3991 *stmt_schema_name =
unconstify(
char *, context_schema);
3992 else if (strcmp(context_schema, *stmt_schema_name) != 0)
3994 (
errcode(ERRCODE_INVALID_SCHEMA_DEFINITION),
3995 errmsg(
"CREATE specifies a schema (%s) "
3996 "different from the one being created (%s)",
3997 *stmt_schema_name, context_schema)));
4012 switch (parentRel->
rd_rel->relkind)
4014 case RELKIND_PARTITIONED_TABLE:
4017 if (cmd->
bound != NULL)
4021 case RELKIND_PARTITIONED_INDEX:
4027 if (cmd->
bound != NULL)
4029 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4030 errmsg(
"\"%s\" is not a partitioned table",
4033 case RELKIND_RELATION:
4036 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4037 errmsg(
"table \"%s\" is not partitioned",
4043 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4044 errmsg(
"index \"%s\" is not partitioned",
4049 elog(
ERROR,
"\"%s\" is not a partitioned table or index",
4083 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4084 errmsg(
"a hash-partitioned table may not have a default partition")));
4100 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4101 errmsg(
"invalid bound specification for a hash partition"),
4104 if (spec->modulus <= 0)
4106 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4107 errmsg(
"modulus for hash partition must be an integer value greater than zero")));
4109 Assert(spec->remainder >= 0);
4111 if (spec->remainder >= spec->modulus)
4113 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4114 errmsg(
"remainder for hash partition must be less than modulus")));
4126 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4127 errmsg(
"invalid bound specification for a list partition"),
4131 if (
key->partattrs[0] != 0)
4133 key->partattrs[0],
false);
4145 foreach(cell, spec->listdatums)
4153 colname, coltype, coltypmod,
4179 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4180 errmsg(
"invalid bound specification for a range partition"),
4185 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4186 errmsg(
"FROM must specify exactly one value per partitioning column")));
4189 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4190 errmsg(
"TO must specify exactly one value per partitioning column")));
4204 elog(
ERROR,
"unexpected partition strategy: %d", (
int) strategy);
4257 else if (strcmp(
"minvalue",
cname) == 0)
4263 else if (strcmp(
"maxvalue",
cname) == 0)
4280 if (
key->partattrs[
i] != 0)
4282 key->partattrs[
i],
false);
4301 if (
value->constisnull)
4303 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4304 errmsg(
"cannot specify NULL in range bound")));
4313 result =
lappend(result, prd);
4341 if (kind == prd->
kind)
4352 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4353 errmsg(
"every bound following MAXVALUE must also be MAXVALUE"),
4359 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4360 errmsg(
"every bound following MINVALUE must also be MINVALUE"),
4372 const char *colName,
Oid colType,
int32 colTypmod,
4402 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4403 errmsg(
"specified value cannot be cast to type %s for column \"%s\"",
4418 elog(
ERROR,
"could not evaluate partition bound expression");
4428 ((
Const *)
value)->constcollid = partCollation;
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Oid get_index_am_oid(const char *amname, bool missing_ok)
#define DatumGetArrayTypeP(X)
void deconstruct_array_builtin(ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
AttrMap * build_attrmap_by_name(TupleDesc indesc, TupleDesc outdesc, bool missing_ok)
#define AttributeNumberIsValid(attributeNumber)
#define InvalidAttrNumber
char * get_tablespace_name(Oid spc_oid)
#define TextDatumGetCString(d)
#define unconstify(underlying_type, expr)
#define InvalidSubTransactionId
#define Assert(condition)
#define OidIsValid(objectId)
Expr * evaluate_expr(Expr *expr, Oid result_type, int32 result_typmod, Oid result_collation)
List * sequence_options(Oid relid)
void errorConflictingDefElem(DefElem *defel, ParseState *pstate)
int errmsg_internal(const char *fmt,...)
int errdetail(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
bool equal(const void *a, const void *b)
const FormData_pg_attribute * 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 * list_copy(const List *oldlist)
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)
bool type_is_range(Oid typid)
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)
bool type_is_multirange(Oid typid)
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 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 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)
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)
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
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_delete_current(lst, var_or_cell)
static ListCell * list_head(const List *l)
static ListCell * list_last_cell(const List *list)
#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 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