125 Oid heapRelid,
Oid source_statsid);
134 bool isAddConstraint);
136 bool skipValidation);
138 List *constraintList);
140 static void setSchemaName(
char *context_schema,
char **stmt_schema_name);
146 const char *colName,
Oid colType,
int32 colTypmod,
210 (
errcode(ERRCODE_DUPLICATE_TABLE),
211 errmsg(
"relation \"%s\" already exists, skipping",
231 cxt.
stmtType =
"CREATE FOREIGN TABLE";
265 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
266 errmsg(
"cannot create partitioned table as inheritance child")));
292 elog(
ERROR,
"unrecognized node type: %d",
304 save_alist = cxt.
alist;
367 Oid seqtypid,
List *seqoptions,
368 bool for_identity,
bool col_exists,
369 char **snamespace_p,
char **sname_p)
395 foreach(option, seqoptions)
399 if (strcmp(defel->
defname,
"sequence_name") == 0)
403 (
errcode(ERRCODE_SYNTAX_ERROR),
404 errmsg(
"conflicting or redundant options")));
446 (
errmsg(
"%s will create implicit sequence \"%s\" for serial column \"%s.%s\"",
508 (
Node *) attnamelist, -1));
517 *snamespace_p = snamespace;
547 if (strcmp(typname,
"smallserial") == 0 ||
548 strcmp(typname,
"serial2") == 0)
554 else if (strcmp(typname,
"serial") == 0 ||
555 strcmp(typname,
"serial4") == 0)
561 else if (strcmp(typname,
"bigserial") == 0 ||
562 strcmp(typname,
"serial8") == 0)
576 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
577 errmsg(
"array of serial is not implemented"),
600 &snamespace, &sname);
619 castnode->
arg = (
Node *) snamenode;
641 saw_nullable =
false;
643 saw_identity =
false;
644 saw_generated =
false;
655 (
errcode(ERRCODE_SYNTAX_ERROR),
656 errmsg(
"conflicting NULL/NOT NULL declarations for column \"%s\" of table \"%s\"",
667 (
errcode(ERRCODE_SYNTAX_ERROR),
668 errmsg(
"conflicting NULL/NOT NULL declarations for column \"%s\" of table \"%s\"",
679 (
errcode(ERRCODE_SYNTAX_ERROR),
680 errmsg(
"multiple default values specified for column \"%s\" of table \"%s\"",
696 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
697 errmsg(
"identity columns are not supported on typed tables")));
700 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
701 errmsg(
"identity columns are not supported on partitions")));
709 (
errcode(ERRCODE_SYNTAX_ERROR),
710 errmsg(
"multiple identity specifications for column \"%s\" of table \"%s\"",
729 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
730 errmsg(
"generated columns are not supported on typed tables")));
733 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
734 errmsg(
"generated columns are not supported on partitions")));
738 (
errcode(ERRCODE_SYNTAX_ERROR),
739 errmsg(
"multiple generation clauses specified for column \"%s\" of table \"%s\"",
743 column->
generated = ATTRIBUTE_GENERATED_STORED;
746 saw_generated =
true;
756 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
757 errmsg(
"primary key constraints are not supported on foreign tables"),
765 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
766 errmsg(
"unique constraints are not supported on foreign tables"),
776 elog(
ERROR,
"column exclusion constraints are not supported");
782 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
783 errmsg(
"foreign key constraints are not supported on foreign tables"),
803 elog(
ERROR,
"unrecognized constraint type: %d",
808 if (saw_default && saw_identity)
810 (
errcode(ERRCODE_SYNTAX_ERROR),
811 errmsg(
"both default and identity specified for column \"%s\" of table \"%s\"",
816 if (saw_default && saw_generated)
818 (
errcode(ERRCODE_SYNTAX_ERROR),
819 errmsg(
"both default and generation expression specified for column \"%s\" of table \"%s\"",
824 if (saw_identity && saw_generated)
826 (
errcode(ERRCODE_SYNTAX_ERROR),
827 errmsg(
"both identity and generation expression specified for column \"%s\" of table \"%s\"",
871 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
872 errmsg(
"primary key constraints are not supported on foreign tables"),
881 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
882 errmsg(
"unique constraints are not supported on foreign tables"),
891 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
892 errmsg(
"exclusion constraints are not supported on foreign tables"),
897 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
898 errmsg(
"exclusion constraints are not supported on partitioned tables"),
911 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
912 errmsg(
"foreign key constraints are not supported on foreign tables"),
925 elog(
ERROR,
"invalid context for constraint type %d",
930 elog(
ERROR,
"unrecognized constraint type: %d",
962 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
963 errmsg(
"LIKE is not supported for creating foreign tables")));
968 if (relation->
rd_rel->relkind != RELKIND_RELATION &&
969 relation->
rd_rel->relkind != RELKIND_VIEW &&
970 relation->
rd_rel->relkind != RELKIND_MATVIEW &&
971 relation->
rd_rel->relkind != RELKIND_COMPOSITE_TYPE &&
972 relation->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
973 relation->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
975 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
976 errmsg(
"\"%s\" is not a table, view, materialized view, composite type, or foreign table",
984 if (relation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
1008 for (parent_attno = 1; parent_attno <= tupleDesc->
natts;
1013 char *attributeName =
NameStr(attribute->attname);
1019 if (attribute->attisdropped)
1031 attribute->atttypmod);
1040 def->
collOid = attribute->attcollation;
1053 if (attribute->atthasdef && attribute->attgenerated &&
1055 def->
generated = attribute->attgenerated;
1060 if (attribute->attidentity &&
1076 def->
identity = attribute->attidentity;
1081 def->
storage = attribute->attstorage;
1089 attribute->attnum)) != NULL)
1111 if (table_like_clause->
options &
1127 List *parent_extstats;
1132 foreach(l, parent_extstats)
1144 comment =
GetComment(parent_stat_oid, StatisticExtRelationId, 0);
1196 elog(
ERROR,
"expandTableLikeClause called on untransformed LIKE clause");
1201 constr = tupleDesc->
constr;
1219 if ((table_like_clause->
options &
1225 for (parent_attno = 1; parent_attno <= tupleDesc->
natts;
1234 if (attribute->attisdropped)
1242 if (attribute->atthasdef &&
1243 (attribute->attgenerated ?
1247 Node *this_default = NULL;
1249 bool found_whole_row;
1254 if (attrdef[
i].adnum == parent_attno)
1260 Assert(this_default != NULL);
1264 atsubcmd->
num = attmap->
attnums[parent_attno - 1];
1276 if (found_whole_row)
1278 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1279 errmsg(
"cannot convert whole-row table reference"),
1280 errdetail(
"Generation expression for column \"%s\" contains a whole-row reference to table \"%s\".",
1284 atsubcmds =
lappend(atsubcmds, atsubcmd);
1298 for (ccnum = 0; ccnum < constr->
num_check; ccnum++)
1304 bool found_whole_row;
1319 if (found_whole_row)
1321 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1322 errmsg(
"cannot convert whole-row table reference"),
1323 errdetail(
"Constraint \"%s\" contains a whole-row reference to table \"%s\".",
1342 atsubcmds =
lappend(atsubcmds, atsubcmd);
1348 ConstraintRelationId,
1359 result =
lappend(result, stmt);
1374 atcmd->
cmds = atsubcmds;
1377 result =
lcons(atcmd, result);
1384 relation->
rd_rel->relhasindex)
1386 List *parent_indexes;
1391 foreach(l, parent_indexes)
1408 comment =
GetComment(parent_index_oid, RelationRelationId, 0);
1417 result =
lappend(result, index_stmt);
1449 ofTypename->
typeOid = ofTypeId;
1452 for (i = 0; i < tupdesc->
natts; i++)
1457 if (attr->attisdropped)
1471 n->
collOid = attr->attcollation;
1531 elog(
ERROR,
"cache lookup failed for relation %u", source_relid);
1537 indrelid = idxrec->indrelid;
1542 elog(
ERROR,
"cache lookup failed for access method %u",
1548 Anum_pg_index_indcollation, &isnull);
1554 Anum_pg_index_indclass, &isnull);
1572 index->
unique = idxrec->indisunique;
1573 index->
primary = idxrec->indisprimary;
1593 if (index->
primary || index->
unique || idxrec->indisexclusion)
1603 *constraintOid = constraintId;
1608 elog(
ERROR,
"cache lookup failed for constraint %u",
1617 if (idxrec->indisexclusion)
1623 Assert(conrec->contype == CONSTRAINT_EXCLUSION);
1626 Anum_pg_constraint_conexclop,
1629 elog(
ERROR,
"null conexclop for constraint %u",
1633 OIDOID,
sizeof(
Oid),
true, TYPALIGN_INT,
1634 &elems, NULL, &nElems);
1636 for (i = 0; i < nElems; i++)
1648 elog(
ERROR,
"cache lookup failed for operator %u",
1672 Anum_pg_index_indexprs, &isnull);
1688 for (keyno = 0; keyno < idxrec->indnkeyatts; keyno++)
1707 iparam->
expr = NULL;
1713 bool found_whole_row;
1715 if (indexpr_item == NULL)
1716 elog(
ERROR,
"too few entries in indexprs list");
1718 indexpr_item =
lnext(indexprs, indexpr_item);
1727 if (found_whole_row)
1729 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1730 errmsg(
"cannot convert whole-row table reference"),
1731 errdetail(
"Index \"%s\" contains a whole-row table reference.",
1734 iparam->
name = NULL;
1735 iparam->
expr = indexkey;
1763 if (opt & INDOPTION_DESC)
1766 if ((opt & INDOPTION_NULLS_FIRST) == 0)
1771 if (opt & INDOPTION_NULLS_FIRST)
1780 for (keyno = idxrec->indnkeyatts; keyno < idxrec->indnatts; keyno++)
1797 iparam->
expr = NULL;
1801 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1802 errmsg(
"expressions are not supported in included columns")));
1811 Anum_pg_class_reloptions, &isnull);
1817 Anum_pg_index_indpred, &isnull);
1822 bool found_whole_row;
1835 if (found_whole_row)
1837 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1838 errmsg(
"cannot convert whole-row table reference"),
1839 errdetail(
"Index \"%s\" contains a whole-row table reference.",
1880 elog(
ERROR,
"cache lookup failed for statistics object %u", source_statsid);
1885 Anum_pg_statistic_ext_stxkind, &isnull);
1891 elog(
ERROR,
"stxkind is not a 1-D char array");
1893 for (i = 0; i <
ARR_DIMS(arr)[0]; i++)
1895 if (enabled[i] == STATS_EXT_NDISTINCT)
1897 else if (enabled[i] == STATS_EXT_DEPENDENCIES)
1899 else if (enabled[i] == STATS_EXT_MCV)
1902 elog(
ERROR,
"unrecognized statistics kind %c", enabled[i]);
1906 for (i = 0; i < statsrec->stxkeys.dim1; i++)
1915 def_names =
lappend(def_names, cref);
1922 stats->
exprs = def_names;
1955 elog(
ERROR,
"cache lookup failed for collation %u", collation);
1982 elog(
ERROR,
"cache lookup failed for opclass %u", opclass);
2029 indexlist =
lappend(indexlist, index);
2041 if (cxt->
pkey != NULL)
2047 foreach(lc, indexlist)
2055 if (index == cxt->
pkey)
2058 foreach(k, finalindexlist)
2078 if (priorindex->
idxname == NULL)
2086 finalindexlist =
lappend(finalindexlist, index);
2120 if (cxt->
pkey != NULL)
2122 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
2123 errmsg(
"multiple primary keys for table \"%s\" are not allowed",
2137 if (constraint->
conname != NULL)
2168 char *index_name = constraint->
indexname;
2174 Datum indclassDatum;
2188 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2189 errmsg(
"cannot use an existing index in CREATE TABLE"),
2197 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2198 errmsg(
"index \"%s\" does not exist", index_name),
2208 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2209 errmsg(
"index \"%s\" is already associated with a constraint",
2216 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2217 errmsg(
"index \"%s\" does not belong to table \"%s\"",
2221 if (!index_form->indisvalid)
2223 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2224 errmsg(
"index \"%s\" is not valid", index_name),
2227 if (!index_form->indisunique)
2229 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2230 errmsg(
"\"%s\" is not a unique index", index_name),
2231 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2236 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2237 errmsg(
"index \"%s\" contains expressions", index_name),
2238 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2243 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2244 errmsg(
"\"%s\" is a partial index", index_name),
2245 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2253 if (!index_form->indimmediate && !constraint->
deferrable)
2255 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2256 errmsg(
"\"%s\" is a deferrable index", index_name),
2257 errdetail(
"Cannot create a non-deferrable constraint using a deferrable index."),
2269 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2270 errmsg(
"index \"%s\" is not a btree", index_name),
2275 Anum_pg_index_indclass, &isnull);
2279 for (i = 0; i < index_form->indnatts; i++)
2293 Assert(attnum <= heap_rel->rd_att->natts);
2300 if (i < index_form->indnkeyatts)
2314 index_rel->
rd_rel->relam);
2315 if (indclass->
values[i] != defopclass ||
2317 attoptions != (
Datum) 0 ||
2320 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2321 errmsg(
"index \"%s\" column number %d does not have default sorting behavior", index_name, i + 1),
2322 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2367 foreach(lc, constraint->
keys)
2371 bool forced_not_null =
false;
2377 foreach(columns, cxt->
columns)
2380 if (strcmp(column->
colname, key) == 0)
2398 forced_not_null =
true;
2423 if (rel->
rd_rel->relkind != RELKIND_RELATION &&
2424 rel->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2425 rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2427 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2428 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2430 for (count = 0; count < rel->
rd_att->
natts; count++)
2434 char *inhname =
NameStr(inhattr->attname);
2436 if (inhattr->attisdropped)
2438 if (strcmp(key, inhname) == 0)
2465 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2466 errmsg(
"column \"%s\" named in key does not exist", key),
2473 if (iparam->
name && strcmp(key, iparam->
name) == 0)
2477 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2478 errmsg(
"column \"%s\" appears twice in primary key constraint",
2483 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2484 errmsg(
"column \"%s\" appears twice in unique constraint",
2493 iparam->
expr = NULL;
2512 notnullcmds =
lappend(notnullcmds, notnullcmd);
2532 foreach(columns, cxt->
columns)
2535 if (strcmp(column->
colname, key) == 0)
2565 if (rel->
rd_rel->relkind != RELKIND_RELATION &&
2566 rel->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2567 rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2569 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2570 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2572 for (count = 0; count < rel->
rd_att->
natts; count++)
2576 char *inhname =
NameStr(inhattr->attname);
2578 if (inhattr->attisdropped)
2580 if (strcmp(key, inhname) == 0)
2600 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2601 errmsg(
"column \"%s\" named in key does not exist", key),
2607 iparam->
expr = NULL;
2624 alterstmt->
cmds = notnullcmds;
2687 bool skipValidation,
bool isAddConstraint)
2721 if (!isAddConstraint)
2735 altercmd->
name = NULL;
2736 altercmd->
def = (
Node *) constraint;
2836 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
2837 errmsg(
"index expressions and predicates can refer only to the table being indexed")));
2865 List **actions,
Node **whereClause)
2880 if (rel->
rd_rel->relkind == RELKIND_MATVIEW)
2882 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2883 errmsg(
"rules on materialized views are not supported")));
2913 switch (stmt->
event)
2929 elog(
ERROR,
"unrecognized event type: %d",
2945 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2946 errmsg(
"rule WHERE condition cannot contain references to other relations")));
3017 *whereClause != NULL)
3019 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3020 errmsg(
"rules with WHERE conditions can only have SELECT, INSERT, UPDATE, or DELETE actions")));
3037 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3038 errmsg(
"conditional UNION/INTERSECT/EXCEPT statements are not implemented")));
3050 switch (stmt->
event)
3055 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3056 errmsg(
"ON SELECT rule cannot use OLD")));
3059 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3060 errmsg(
"ON SELECT rule cannot use NEW")));
3068 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3069 errmsg(
"ON INSERT rule cannot use OLD")));
3074 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3075 errmsg(
"ON DELETE rule cannot use NEW")));
3078 elog(
ERROR,
"unrecognized event type: %d",
3102 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3103 errmsg(
"cannot refer to OLD within WITH query")));
3109 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3110 errmsg(
"cannot refer to NEW within WITH query")));
3136 if (sub_qry->setOperations != NULL)
3138 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3139 errmsg(
"conditional UNION/INTERSECT/EXCEPT statements are not implemented")));
3143 sub_qry->jointree->fromlist =
3144 lappend(sub_qry->jointree->fromlist, rtr);
3147 newactions =
lappend(newactions, top_subqry);
3152 *actions = newactions;
3176 const char *queryString,
3177 List **beforeStmts,
List **afterStmts)
3187 bool skipValidation =
true;
3214 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
3216 cxt.
stmtType =
"ALTER FOREIGN TABLE";
3245 foreach(lcmd, stmt->
cmds)
3263 skipValidation =
false;
3271 newcmds =
lappend(newcmds, cmd);
3285 skipValidation =
false;
3288 elog(
ERROR,
"unrecognized node type: %d",
3315 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3316 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
3333 newcmds =
lappend(newcmds, cmd);
3350 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3351 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
3359 newcmds =
lappend(newcmds, cmd);
3383 if (strcmp(def->
defname,
"generated") == 0)
3384 newdef =
lappend(newdef, def);
3386 newseqopts =
lappend(newseqopts, def);
3392 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3393 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
3405 seqstmt->
options = newseqopts;
3421 newcmds =
lappend(newcmds, cmd);
3435 newcmds =
lappend(newcmds, cmd);
3445 newcmds =
lappend(newcmds, cmd);
3454 save_alist = cxt.
alist;
3468 foreach(l, cxt.
alist)
3484 newcmd->
def = (
Node *) idxstmt;
3485 newcmds =
lappend(newcmds, newcmd);
3504 newcmds =
lappend(newcmds, newcmd);
3511 newcmds =
lappend(newcmds, newcmd);
3523 stmt->
cmds = newcmds;
3525 *beforeStmts = cxt.
blist;
3545 bool saw_deferrability =
false;
3546 bool saw_initially =
false;
3549 #define SUPPORTS_ATTRS(node) \ 3550 ((node) != NULL && \ 3551 ((node)->contype == CONSTR_PRIMARY || \ 3552 (node)->contype == CONSTR_UNIQUE || \ 3553 (node)->contype == CONSTR_EXCLUSION || \ 3554 (node)->contype == CONSTR_FOREIGN)) 3556 foreach(clist, constraintList)
3561 elog(
ERROR,
"unrecognized node type: %d",
3568 (
errcode(ERRCODE_SYNTAX_ERROR),
3569 errmsg(
"misplaced DEFERRABLE clause"),
3571 if (saw_deferrability)
3573 (
errcode(ERRCODE_SYNTAX_ERROR),
3574 errmsg(
"multiple DEFERRABLE/NOT DEFERRABLE clauses not allowed"),
3576 saw_deferrability =
true;
3583 (
errcode(ERRCODE_SYNTAX_ERROR),
3584 errmsg(
"misplaced NOT DEFERRABLE clause"),
3586 if (saw_deferrability)
3588 (
errcode(ERRCODE_SYNTAX_ERROR),
3589 errmsg(
"multiple DEFERRABLE/NOT DEFERRABLE clauses not allowed"),
3591 saw_deferrability =
true;
3593 if (saw_initially &&
3596 (
errcode(ERRCODE_SYNTAX_ERROR),
3597 errmsg(
"constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3604 (
errcode(ERRCODE_SYNTAX_ERROR),
3605 errmsg(
"misplaced INITIALLY DEFERRED clause"),
3609 (
errcode(ERRCODE_SYNTAX_ERROR),
3610 errmsg(
"multiple INITIALLY IMMEDIATE/DEFERRED clauses not allowed"),
3612 saw_initially =
true;
3618 if (!saw_deferrability)
3622 (
errcode(ERRCODE_SYNTAX_ERROR),
3623 errmsg(
"constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3630 (
errcode(ERRCODE_SYNTAX_ERROR),
3631 errmsg(
"misplaced INITIALLY IMMEDIATE clause"),
3635 (
errcode(ERRCODE_SYNTAX_ERROR),
3636 errmsg(
"multiple INITIALLY IMMEDIATE/DEFERRED clauses not allowed"),
3638 saw_initially =
true;
3644 lastprimarycon = con;
3646 saw_deferrability =
false;
3647 saw_initially =
false;
3675 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3676 errmsg(
"collations are not supported by type %s",
3794 elog(
ERROR,
"unrecognized node type: %d",
3817 if (*stmt_schema_name == NULL)
3818 *stmt_schema_name = context_schema;
3819 else if (strcmp(context_schema, *stmt_schema_name) != 0)
3821 (
errcode(ERRCODE_INVALID_SCHEMA_DEFINITION),
3822 errmsg(
"CREATE specifies a schema (%s) " 3823 "different from the one being created (%s)",
3824 *stmt_schema_name, context_schema)));
3839 switch (parentRel->
rd_rel->relkind)
3841 case RELKIND_PARTITIONED_TABLE:
3844 if (cmd->
bound != NULL)
3848 case RELKIND_PARTITIONED_INDEX:
3854 if (cmd->
bound != NULL)
3856 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3857 errmsg(
"\"%s\" is not a partitioned table",
3860 case RELKIND_RELATION:
3863 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3864 errmsg(
"table \"%s\" is not partitioned",
3870 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3871 errmsg(
"index \"%s\" is not partitioned",
3876 elog(
ERROR,
"\"%s\" is not a partitioned table or index",
3910 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3911 errmsg(
"a hash-partitioned table may not have a default partition")));
3927 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3928 errmsg(
"invalid bound specification for a hash partition"),
3931 if (spec->modulus <= 0)
3933 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3934 errmsg(
"modulus for hash partition must be a positive integer")));
3936 Assert(spec->remainder >= 0);
3938 if (spec->remainder >= spec->modulus)
3940 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3941 errmsg(
"remainder for hash partition must be less than modulus")));
3953 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
3954 errmsg(
"invalid bound specification for a list partition"),
3972 foreach(cell, spec->listdatums)
3980 colname, coltype, coltypmod,
3989 if (
equal(value, value2))
4006 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4007 errmsg(
"invalid bound specification for a range partition"),
4012 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4013 errmsg(
"FROM must specify exactly one value per partitioning column")));
4016 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4017 errmsg(
"TO must specify exactly one value per partitioning column")));
4031 elog(
ERROR,
"unexpected partition strategy: %d", (
int) strategy);
4084 else if (strcmp(
"minvalue", cname) == 0)
4090 else if (strcmp(
"maxvalue", cname) == 0)
4130 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4131 errmsg(
"cannot specify NULL in range bound")));
4140 result =
lappend(result, prd);
4168 if (kind == prd->
kind)
4179 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4180 errmsg(
"every bound following MAXVALUE must also be MAXVALUE"),
4186 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4187 errmsg(
"every bound following MINVALUE must also be MINVALUE"),
4199 const char *colName,
Oid colType,
int32 colTypmod,
4229 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4230 errmsg(
"specified value cannot be cast to type %s for column \"%s\"",
4245 elog(
ERROR,
"could not evaluate partition bound expression");
4255 ((
Const *) value)->constcollid = partCollation;
#define list_make2(x1, x2)
Value * makeString(char *str)
#define list_make3(x1, x2, x3)
Expr * evaluate_expr(Expr *expr, Oid result_type, int32 result_typmod, Oid result_collation)
static List * get_opclass(Oid opclass, Oid actual_datatype)
struct IndexAmRoutine * rd_indam
Query * getInsertSelectQuery(Query *parsetree, Query ***subquery_ptr)
List * SystemFuncName(char *name)
FromExpr * makeFromExpr(List *fromlist, Node *quals)
#define IsA(nodeptr, _type_)
void table_close(Relation relation, LOCKMODE lockmode)
Oid GetDefaultOpClass(Oid type_id, Oid am_id)
Type typenameType(ParseState *pstate, const TypeName *typeName, int32 *typmod_p)
static void generateSerialExtraStmts(CreateStmtContext *cxt, ColumnDef *column, Oid seqtypid, List *seqoptions, bool for_identity, bool col_exists, char **snamespace_p, char **sname_p)
int exprLocation(const Node *expr)
SubTransactionId oldCreateSubid
TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod)
static ListCell * lnext(const List *l, const ListCell *c)
bool equal(const void *a, const void *b)
#define RelationGetDescr(relation)
#define castNode(_type_, nodeptr)
Oid get_relation_constraint_oid(Oid relid, const char *conname, bool missing_ok)
static int32 get_partition_col_typmod(PartitionKey key, int col)
#define TupleDescAttr(tupdesc, i)
#define DatumGetObjectId(X)
char * pstrdup(const char *in)
static Oid get_partition_col_typid(PartitionKey key, int col)
Oid get_rel_namespace(Oid relid)
Expr * expression_planner(Expr *expr)
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
PartitionRangeDatumKind kind
void addNSItemToQuery(ParseState *pstate, ParseNamespaceItem *nsitem, bool addToJoinList, bool addToRelNameSpace, bool addToVarNameSpace)
static int get_partition_natts(PartitionKey key)
List * list_concat(List *list1, const List *list2)
int errcode(int sqlerrcode)
char * FigureIndexColname(Node *node)
void * stringToNode(const char *str)
static CreateStatsStmt * generateClonedExtStatsStmt(RangeVar *heapRel, Oid heapRelid, Oid source_statsid)
RangeVar * makeRangeVarFromNameList(List *names)
bool contain_var_clause(Node *node)
char * ChooseRelationName(const char *name1, const char *name2, const char *label, Oid namespaceid, bool isconstraint)
Node * map_variable_attnos(Node *node, int target_varno, int sublevels_up, const AttrMap *attno_map, Oid to_rowtype, bool *found_whole_row)
PartitionKey RelationGetPartitionKey(Relation rel)
#define linitial_node(type, l)
Oid getIdentitySequence(Oid relid, AttrNumber attnum, bool missing_ok)
#define OidIsValid(objectId)
DefElem * makeDefElem(char *name, Node *arg, int location)
void RangeVarAdjustRelationPersistence(RangeVar *newRelation, Oid nspid)
List * RelationGetIndexPredicate(Relation relation)
struct HeapTupleData * rd_indextuple
ParseNamespaceItem * addRangeTableEntryForRelation(ParseState *pstate, Relation rel, int lockmode, Alias *alias, bool inh, bool inFromCl)
ParseState * make_parsestate(ParseState *parentParseState)
List * indexIncludingParams
const FormData_pg_attribute * SystemAttributeDefinition(AttrNumber attno)
PartitionBoundSpec * transformPartitionBound(ParseState *pstate, Relation parent, PartitionBoundSpec *spec)
RangeVar * identitySequence
void assign_expr_collations(ParseState *pstate, Node *expr)
PartitionBoundSpec * partbound
Alias * makeAlias(const char *aliasname, List *colnames)
static List * get_partition_exprs(PartitionKey key)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Datum get_attoptions(Oid relid, int16 attnum)
void cancel_parser_errposition_callback(ParseCallbackState *pcbstate)
SortByNulls nulls_ordering
#define ObjectIdGetDatum(X)
static Const * transformPartitionBoundValue(ParseState *pstate, Node *con, const char *colName, Oid colType, int32 colTypmod, Oid partCollation)
static void transformConstraintAttrs(CreateStmtContext *cxt, List *constraintList)
static void * list_nth(const List *list, int n)
static List * transformPartitionRangeBounds(ParseState *pstate, List *blist, Relation parent)
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
Relation relation_open(Oid relationId, LOCKMODE lockmode)
void check_of_type(HeapTuple typetuple)
Oid get_relname_relid(const char *relname, Oid relnamespace)
#define lfirst_node(type, lc)
const FormData_pg_attribute * SystemAttributeByName(const char *attname)
static void validateInfiniteBounds(ParseState *pstate, List *blist)
char * get_namespace_name(Oid nspid)
Oid get_index_am_oid(const char *amname, bool missing_ok)
AttrNumber get_attnum(Oid relid, const char *attname)
List * RelationGetIndexExpressions(Relation relation)
Oid values[FLEXIBLE_ARRAY_MEMBER]
union Value::ValUnion val
List * deparse_context_for(const char *aliasname, Oid relid)
int errdetail(const char *fmt,...)
#define DEFAULT_INDEX_TYPE
#define RelationGetRelationName(relation)
static ListCell * list_head(const List *l)
FormData_pg_attribute * Form_pg_attribute
static void transformColumnType(CreateStmtContext *cxt, ColumnDef *column)
Oid get_index_constraint(Oid indexId)
SubTransactionId oldFirstRelfilenodeSubid
bool reset_default_tblspc
const char * p_sourcetext
Oid get_atttype(Oid relid, AttrNumber attnum)
#define AssertArg(condition)
void setup_parser_errposition_callback(ParseCallbackState *pcbstate, ParseState *pstate, int location)
PartitionBoundSpec * partbound
Query * transformStmt(ParseState *pstate, Node *parseTree)
List * lappend(List *list, void *datum)
static chr element(struct vars *v, const chr *startp, const chr *endp)
char * quote_qualified_identifier(const char *qualifier, const char *ident)
FormData_pg_index * Form_pg_index
HeapTuple SearchSysCache1(int cacheId, Datum key1)
#define AttributeNumberIsValid(attributeNumber)
Oid RangeVarGetAndCheckCreationNamespace(RangeVar *relation, LOCKMODE lockmode, Oid *existing_relation_id)
FuncCall * makeFuncCall(List *name, List *args, CoercionForm funcformat, int location)
TypeName * SystemTypeName(char *name)
#define TextDatumGetCString(d)
bool reset_default_tblspc
#define lsecond_node(type, l)
void ReleaseSysCache(HeapTuple tuple)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
static IndexStmt * transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
List * untransformRelOptions(Datum options)
#define PARTITION_STRATEGY_HASH
List * expandTableLikeClause(RangeVar *heapRel, TableLikeClause *table_like_clause)
Oid LookupCollation(ParseState *pstate, List *collnames, int location)
TypeName * makeTypeNameFromOid(Oid typeOid, int32 typmod)
Relation table_openrv(const RangeVar *relation, LOCKMODE lockmode)
#define ereport(elevel,...)
Oid get_typcollation(Oid typid)
AttrMap * build_attrmap_by_name(TupleDesc indesc, TupleDesc outdesc)
List * lcons(void *datum, List *list)
static void transformOfType(CreateStmtContext *cxt, TypeName *ofTypename)
FormData_pg_constraint * Form_pg_constraint
#define HeapTupleIsValid(tuple)
void relation_close(Relation relation, LOCKMODE lockmode)
#define Assert(condition)
static void setSchemaName(char *context_schema, char **stmt_schema_name)
static void transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
void DecrTupleDescRefCount(TupleDesc tupdesc)
IndexStmt * generateClonedIndexStmt(RangeVar *heapRel, Relation source_idx, const AttrMap *attmap, Oid *constraintOid)
Node * transformWhereClause(ParseState *pstate, Node *clause, ParseExprKind exprKind, const char *constructName)
PartitionBoundSpec * bound
char * deparse_expression(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit)
Oid exprType(const Node *expr)
FormData_pg_type * Form_pg_type
static int list_length(const List *l)
List * transformCreateStmt(CreateStmt *stmt, const char *queryString)
int parser_errposition(ParseState *pstate, int location)
AlterTableStmt * transformAlterTableStmt(Oid relid, AlterTableStmt *stmt, const char *queryString, List **beforeStmts, List **afterStmts)
CollateClause * collClause
#define InvalidSubTransactionId
static void transformPartitionCmd(CreateStmtContext *cxt, PartitionCmd *cmd)
#define PARTITION_STRATEGY_LIST
List * RelationGetIndexList(Relation relation)
FormData_pg_operator * Form_pg_operator
static void transformFKConstraints(CreateStmtContext *cxt, bool skipValidation, bool isAddConstraint)
#define InvalidAttrNumber
FormData_pg_collation * Form_pg_collation
List * RelationGetStatExtList(Relation relation)
static void transformExtendedStatistics(CreateStmtContext *cxt)
void index_close(Relation relation, LOCKMODE lockmode)
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
#define DatumGetPointer(X)
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
static Oid get_partition_col_collation(PartitionKey key, int col)
FormData_pg_class * Form_pg_class
#define PARTITION_STRATEGY_RANGE
List * transformCreateSchemaStmt(CreateSchemaStmt *stmt)
#define AccessExclusiveLock
FormData_pg_am * Form_pg_am
int errmsg(const char *fmt,...)
char * get_tablespace_name(Oid spc_oid)
void list_free(List *list)
#define SUPPORTS_ATTRS(node)
ObjectType get_relkind_objtype(char relkind)
char * nodeToString(const void *obj)
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
bool rangeTableEntry_used(Node *node, int rt_index, int sublevels_up)
static int get_partition_strategy(PartitionKey key)
List * list_delete_nth_cell(List *list, int n)
AclResult pg_type_aclcheck(Oid type_oid, Oid roleid, AclMode mode)
static void transformTableConstraint(CreateStmtContext *cxt, Constraint *constraint)
void free_parsestate(ParseState *pstate)
static void transformIndexConstraints(CreateStmtContext *cxt)
IndexStmt * transformIndexStmt(Oid relid, IndexStmt *stmt, const char *queryString)
List * sequence_options(Oid relid)
static List * get_collation(Oid collation, Oid actual_datatype)
FormData_pg_opclass * Form_pg_opclass
char * get_rel_name(Oid relid)
static void transformTableLikeClause(CreateStmtContext *cxt, TableLikeClause *table_like_clause)
#define RelationGetRelid(relation)
void transformRuleStmt(RuleStmt *stmt, const char *queryString, List **actions, Node **whereClause)
Relation index_open(Oid relationId, LOCKMODE lockmode)
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
static void transformCheckConstraints(CreateStmtContext *cxt, bool skipValidation)
Oid RangeVarGetCreationNamespace(const RangeVar *newRelation)
FormData_pg_statistic_ext * Form_pg_statistic_ext
#define foreach_current_index(cell)
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
#define RelationGetNamespace(relation)
#define DatumGetArrayTypeP(X)