121 Oid heapRelid,
Oid source_statsid);
130 bool isAddConstraint);
132 bool skipValidation);
134 List *constraintList);
136 static void setSchemaName(
const char *context_schema,
char **stmt_schema_name);
142 const char *colName,
Oid colType,
int32 colTypmod,
186 stmt->relation->location);
209 (
errcode(ERRCODE_DUPLICATE_TABLE),
210 errmsg(
"relation \"%s\" already exists, skipping",
211 stmt->relation->relname)));
222 if (
stmt->relation->schemaname == NULL
223 &&
stmt->relation->relpersistence != RELPERSISTENCE_TEMP)
230 cxt.
stmtType =
"CREATE FOREIGN TABLE";
258 if (
stmt->ofTypename)
263 if (
stmt->inhRelations && !
stmt->partbound)
265 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
266 errmsg(
"cannot create partitioned table as inheritance child")));
273 foreach(elements,
stmt->tableElts)
287 case T_TableLikeClause:
292 elog(
ERROR,
"unrecognized node type: %d",
304 save_alist = cxt.
alist;
371 Oid seqtypid,
List *seqoptions,
372 bool for_identity,
bool col_exists,
373 char **snamespace_p,
char **sname_p)
402 foreach(
option, seqoptions)
406 if (strcmp(defel->
defname,
"sequence_name") == 0)
451 (
errmsg_internal(
"%s will create implicit sequence \"%s\" for serial column \"%s.%s\"",
514 (
Node *) attnamelist, -1));
523 *snamespace_p = snamespace;
541 bool need_notnull =
false;
554 if (strcmp(
typname,
"smallserial") == 0 ||
555 strcmp(
typname,
"serial2") == 0)
561 else if (strcmp(
typname,
"serial") == 0 ||
562 strcmp(
typname,
"serial4") == 0)
568 else if (strcmp(
typname,
"bigserial") == 0 ||
569 strcmp(
typname,
"serial8") == 0)
583 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
584 errmsg(
"array of serial is not implemented"),
607 &snamespace, &sname);
626 castnode->
arg = (
Node *) snamenode;
646 saw_nullable =
false;
648 saw_identity =
false;
649 saw_generated =
false;
658 if ((saw_nullable && column->
is_not_null) || need_notnull)
660 (
errcode(ERRCODE_SYNTAX_ERROR),
661 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\"",
697 need_notnull =
false;
705 (
errcode(ERRCODE_SYNTAX_ERROR),
706 errmsg(
"multiple default values specified for column \"%s\" of table \"%s\"",
722 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
723 errmsg(
"identity columns are not supported on typed tables")));
726 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
727 errmsg(
"identity columns are not supported on partitions")));
735 (
errcode(ERRCODE_SYNTAX_ERROR),
736 errmsg(
"multiple identity specifications for column \"%s\" of table \"%s\"",
757 (
errcode(ERRCODE_SYNTAX_ERROR),
758 errmsg(
"conflicting NULL/NOT NULL declarations for column \"%s\" of table \"%s\"",
768 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
769 errmsg(
"generated columns are not supported on typed tables")));
772 (
errcode(ERRCODE_SYNTAX_ERROR),
773 errmsg(
"multiple generation clauses specified for column \"%s\" of table \"%s\"",
777 column->
generated = ATTRIBUTE_GENERATED_STORED;
780 saw_generated =
true;
790 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
791 errmsg(
"primary key constraints are not supported on foreign tables"),
799 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
800 errmsg(
"unique constraints are not supported on foreign tables"),
810 elog(
ERROR,
"column exclusion constraints are not supported");
816 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
817 errmsg(
"foreign key constraints are not supported on foreign tables"),
837 elog(
ERROR,
"unrecognized constraint type: %d",
842 if (saw_default && saw_identity)
844 (
errcode(ERRCODE_SYNTAX_ERROR),
845 errmsg(
"both default and identity specified for column \"%s\" of table \"%s\"",
850 if (saw_default && saw_generated)
852 (
errcode(ERRCODE_SYNTAX_ERROR),
853 errmsg(
"both default and generation expression specified for column \"%s\" of table \"%s\"",
858 if (saw_identity && saw_generated)
860 (
errcode(ERRCODE_SYNTAX_ERROR),
861 errmsg(
"both identity and generation expression specified for column \"%s\" of table \"%s\"",
871 if (need_notnull && !(saw_nullable && column->
is_not_null))
928 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
929 errmsg(
"primary key constraints are not supported on foreign tables"),
938 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
939 errmsg(
"unique constraints are not supported on foreign tables"),
948 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
949 errmsg(
"exclusion constraints are not supported on foreign tables"),
966 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
967 errmsg(
"foreign key constraints are not supported on foreign tables"),
979 elog(
ERROR,
"invalid context for constraint type %d",
984 elog(
ERROR,
"unrecognized constraint type: %d",
1009 bool process_notnull_constraints =
false;
1017 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1018 errmsg(
"LIKE is not supported for creating foreign tables")));
1023 if (relation->
rd_rel->relkind != RELKIND_RELATION &&
1024 relation->
rd_rel->relkind != RELKIND_VIEW &&
1025 relation->
rd_rel->relkind != RELKIND_MATVIEW &&
1026 relation->
rd_rel->relkind != RELKIND_COMPOSITE_TYPE &&
1027 relation->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
1028 relation->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1030 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1031 errmsg(
"relation \"%s\" is invalid in LIKE clause",
1040 if (relation->
rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
1064 for (parent_attno = 1; parent_attno <= tupleDesc->
natts;
1074 if (attribute->attisdropped)
1081 attribute->atttypmod, attribute->attcollation);
1088 if (attribute->attnotnull)
1089 process_notnull_constraints =
true;
1100 if (attribute->atthasdef && attribute->attgenerated &&
1102 def->
generated = attribute->attgenerated;
1107 if (attribute->attidentity &&
1123 def->
identity = attribute->attidentity;
1128 def->
storage = attribute->attstorage;
1144 attribute->attnum)) != NULL)
1170 if ((table_like_clause->
options &
1175 process_notnull_constraints)
1240 List *parent_extstats;
1245 foreach(l, parent_extstats)
1300 bool at_pushed =
false;
1311 elog(
ERROR,
"expandTableLikeClause called on untransformed LIKE clause");
1316 constr = tupleDesc->
constr;
1335 if ((table_like_clause->
options &
1339 for (parent_attno = 1; parent_attno <= tupleDesc->
natts;
1348 if (attribute->attisdropped)
1356 if (attribute->atthasdef &&
1357 (attribute->attgenerated ?
1363 bool found_whole_row;
1366 if (this_default == NULL)
1367 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
1372 atsubcmd->
num = attmap->
attnums[parent_attno - 1];
1384 if (found_whole_row)
1386 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1387 errmsg(
"cannot convert whole-row table reference"),
1388 errdetail(
"Generation expression for column \"%s\" contains a whole-row reference to table \"%s\".",
1392 atsubcmds =
lappend(atsubcmds, atsubcmd);
1406 for (ccnum = 0; ccnum < constr->
num_check; ccnum++)
1412 bool found_whole_row;
1427 if (found_whole_row)
1429 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1430 errmsg(
"cannot convert whole-row table reference"),
1431 errdetail(
"Constraint \"%s\" contains a whole-row reference to table \"%s\".",
1450 atsubcmds =
lappend(atsubcmds, atsubcmd);
1456 ConstraintRelationId,
1483 atsubcmds =
lappend(atsubcmds, atsubcmd);
1496 atcmd->
cmds = atsubcmds;
1499 result =
lcons(atcmd, result);
1508 relation->
rd_rel->relhasindex)
1510 List *parent_indexes;
1515 foreach(l, parent_indexes)
1543 atsubcmds =
lappend(atsubcmds, notnullcmd);
1555 atcmd->
cmds = atsubcmds;
1558 result =
lcons(atcmd, result);
1574 result =
lappend(result, index_stmt);
1606 ofTypename->
typeOid = ofTypeId;
1609 for (
i = 0;
i < tupdesc->
natts;
i++)
1614 if (attr->attisdropped)
1618 attr->atttypmod, attr->attcollation);
1678 elog(
ERROR,
"cache lookup failed for relation %u", source_relid);
1684 indrelid = idxrec->indrelid;
1689 elog(
ERROR,
"cache lookup failed for access method %u",
1695 Anum_pg_index_indcollation);
1704 index->relation = heapRel;
1709 index->tableSpace = NULL;
1711 index->idxcomment = NULL;
1716 index->unique = idxrec->indisunique;
1717 index->nulls_not_distinct = idxrec->indnullsnotdistinct;
1718 index->primary = idxrec->indisprimary;
1719 index->transformed =
true;
1720 index->concurrent =
false;
1721 index->if_not_exists =
false;
1722 index->reset_default_tblspc =
false;
1730 index->idxname = NULL;
1738 if (
index->primary ||
index->unique || idxrec->indisexclusion)
1748 *constraintOid = constraintId;
1753 elog(
ERROR,
"cache lookup failed for constraint %u",
1757 index->isconstraint =
true;
1758 index->deferrable = conrec->condeferrable;
1759 index->initdeferred = conrec->condeferred;
1762 if (idxrec->indisexclusion)
1768 Assert(conrec->contype == CONSTRAINT_EXCLUSION);
1771 Anum_pg_constraint_conexclop);
1774 for (
i = 0;
i < nElems;
i++)
1786 elog(
ERROR,
"cache lookup failed for operator %u",
1803 index->isconstraint =
false;
1806 index->isconstraint =
false;
1810 Anum_pg_index_indexprs, &isnull);
1826 for (keyno = 0; keyno < idxrec->indnkeyatts; keyno++)
1845 iparam->
expr = NULL;
1851 bool found_whole_row;
1853 if (indexpr_item == NULL)
1854 elog(
ERROR,
"too few entries in indexprs list");
1856 indexpr_item =
lnext(indexprs, indexpr_item);
1865 if (found_whole_row)
1867 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1868 errmsg(
"cannot convert whole-row table reference"),
1869 errdetail(
"Index \"%s\" contains a whole-row table reference.",
1872 iparam->
name = NULL;
1873 iparam->
expr = indexkey;
1901 if (opt & INDOPTION_DESC)
1904 if ((opt & INDOPTION_NULLS_FIRST) == 0)
1909 if (opt & INDOPTION_NULLS_FIRST)
1918 for (keyno = idxrec->indnkeyatts; keyno < idxrec->indnatts; keyno++)
1935 iparam->
expr = NULL;
1939 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1940 errmsg(
"expressions are not supported in included columns")));
1949 Anum_pg_class_reloptions, &isnull);
1955 Anum_pg_index_indpred, &isnull);
1960 bool found_whole_row;
1973 if (found_whole_row)
1975 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1976 errmsg(
"cannot convert whole-row table reference"),
1977 errdetail(
"Index \"%s\" contains a whole-row table reference.",
1980 index->whereClause = pred_tree;
2018 elog(
ERROR,
"cache lookup failed for statistics object %u", source_statsid);
2023 Anum_pg_statistic_ext_stxkind);
2028 elog(
ERROR,
"stxkind is not a 1-D char array");
2032 if (enabled[
i] == STATS_EXT_NDISTINCT)
2034 else if (enabled[
i] == STATS_EXT_DEPENDENCIES)
2036 else if (enabled[
i] == STATS_EXT_MCV)
2038 else if (enabled[
i] == STATS_EXT_EXPRESSIONS)
2042 elog(
ERROR,
"unrecognized statistics kind %c", enabled[
i]);
2046 for (
i = 0;
i < statsrec->stxkeys.dim1;
i++)
2054 def_names =
lappend(def_names, selem);
2067 Anum_pg_statistic_ext_stxexprs, &isnull);
2085 def_names =
lappend(def_names, selem);
2095 stats->
exprs = def_names;
2129 elog(
ERROR,
"cache lookup failed for collation %u", collation);
2156 elog(
ERROR,
"cache lookup failed for opclass %u", opclass);
2217 if (cxt->
pkey != NULL)
2223 foreach(lc, indexlist)
2234 foreach(k, finalindexlist)
2255 if (priorindex->
idxname == NULL)
2293 if (cxt->
pkey != NULL)
2295 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
2296 errmsg(
"multiple primary keys for table \"%s\" are not allowed",
2307 index->isconstraint =
true;
2311 if (constraint->
conname != NULL)
2314 index->idxname = NULL;
2324 index->idxcomment = NULL;
2329 index->transformed =
false;
2330 index->concurrent =
false;
2331 index->if_not_exists =
false;
2342 char *index_name = constraint->
indexname;
2348 Datum indclassDatum;
2361 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2362 errmsg(
"cannot use an existing index in CREATE TABLE"),
2370 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2371 errmsg(
"index \"%s\" does not exist", index_name),
2381 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2382 errmsg(
"index \"%s\" is already associated with a constraint",
2389 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2390 errmsg(
"index \"%s\" does not belong to table \"%s\"",
2394 if (!index_form->indisvalid)
2396 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
2397 errmsg(
"index \"%s\" is not valid", index_name),
2400 if (!index_form->indisunique)
2402 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2403 errmsg(
"\"%s\" is not a unique index", index_name),
2404 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2409 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2410 errmsg(
"index \"%s\" contains expressions", index_name),
2411 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2416 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2417 errmsg(
"\"%s\" is a partial index", index_name),
2418 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2426 if (!index_form->indimmediate && !constraint->
deferrable)
2428 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2429 errmsg(
"\"%s\" is a deferrable index", index_name),
2430 errdetail(
"Cannot create a non-deferrable constraint using a deferrable index."),
2442 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2443 errmsg(
"index \"%s\" is not a btree", index_name),
2449 Anum_pg_index_indclass);
2452 for (
i = 0;
i < index_form->indnatts;
i++)
2466 Assert(attnum <= heap_rel->rd_att->natts);
2473 if (i < index_form->indnkeyatts)
2487 index_rel->
rd_rel->relam);
2488 if (indclass->
values[
i] != defopclass ||
2490 attoptions != (
Datum) 0 ||
2493 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2494 errmsg(
"index \"%s\" column number %d does not have default sorting behavior", index_name,
i + 1),
2495 errdetail(
"Cannot create a primary key or unique constraint using such an index."),
2507 index->indexOid = index_oid;
2540 foreach(lc, constraint->
keys)
2549 foreach(columns, cxt->
columns)
2596 if (rel->
rd_rel->relkind != RELKIND_RELATION &&
2597 rel->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2598 rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2600 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2601 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2603 for (count = 0; count < rel->
rd_att->
natts; count++)
2607 char *inhname =
NameStr(inhattr->attname);
2609 if (inhattr->attisdropped)
2611 if (strcmp(
key, inhname) == 0)
2630 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2631 errmsg(
"column \"%s\" named in key does not exist",
key),
2635 foreach(columns,
index->indexParams)
2638 if (iparam->
name && strcmp(
key, iparam->
name) == 0)
2642 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2643 errmsg(
"column \"%s\" appears twice in primary key constraint",
2648 (
errcode(ERRCODE_DUPLICATE_COLUMN),
2649 errmsg(
"column \"%s\" appears twice in unique constraint",
2658 iparam->
expr = NULL;
2673 notnullcmds =
lappend(notnullcmds, notnullcmd);
2693 foreach(columns, cxt->
columns)
2726 if (rel->
rd_rel->relkind != RELKIND_RELATION &&
2727 rel->
rd_rel->relkind != RELKIND_FOREIGN_TABLE &&
2728 rel->
rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2730 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
2731 errmsg(
"inherited relation \"%s\" is not a table or foreign table",
2733 for (count = 0; count < rel->
rd_att->
natts; count++)
2737 char *inhname =
NameStr(inhattr->attname);
2739 if (inhattr->attisdropped)
2741 if (strcmp(
key, inhname) == 0)
2761 (
errcode(ERRCODE_UNDEFINED_COLUMN),
2762 errmsg(
"column \"%s\" named in key does not exist",
key),
2768 iparam->
expr = NULL;
2785 alterstmt->
cmds = notnullcmds;
2848 bool skipValidation,
bool isAddConstraint)
2882 if (!isAddConstraint)
2896 altercmd->
name = NULL;
2897 altercmd->
def = (
Node *) constraint;
2926 if (
stmt->transformed)
2947 if (
stmt->whereClause)
2958 foreach(l,
stmt->indexParams)
2991 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
2992 errmsg(
"index expressions and predicates can refer only to the table being indexed")));
3000 stmt->transformed =
true;
3021 if (
stmt->transformed)
3042 foreach(l,
stmt->exprs)
3063 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
3064 errmsg(
"statistics expressions can refer only to the table being referenced")));
3072 stmt->transformed =
true;
3089 List **actions,
Node **whereClause)
3104 if (rel->
rd_rel->relkind == RELKIND_MATVIEW)
3106 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3107 errmsg(
"rules on materialized views are not supported")));
3134 switch (
stmt->event)
3150 elog(
ERROR,
"unrecognized event type: %d",
3166 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3167 errmsg(
"rule WHERE condition cannot contain references to other relations")));
3194 foreach(l,
stmt->actions)
3236 *whereClause != NULL)
3238 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3239 errmsg(
"rules with WHERE conditions can only have SELECT, INSERT, UPDATE, or DELETE actions")));
3256 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3257 errmsg(
"conditional UNION/INTERSECT/EXCEPT statements are not implemented")));
3269 switch (
stmt->event)
3274 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3275 errmsg(
"ON SELECT rule cannot use OLD")));
3278 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3279 errmsg(
"ON SELECT rule cannot use NEW")));
3287 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3288 errmsg(
"ON INSERT rule cannot use OLD")));
3293 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
3294 errmsg(
"ON DELETE rule cannot use NEW")));
3297 elog(
ERROR,
"unrecognized event type: %d",
3321 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3322 errmsg(
"cannot refer to OLD within WITH query")));
3328 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3329 errmsg(
"cannot refer to NEW within WITH query")));
3357 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3358 errmsg(
"conditional UNION/INTERSECT/EXCEPT statements are not implemented")));
3366 newactions =
lappend(newactions, top_subqry);
3371 *actions = newactions;
3395 const char *queryString,
3396 List **beforeStmts,
List **afterStmts)
3406 bool skipValidation =
true;
3427 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
3429 cxt.
stmtType =
"ALTER FOREIGN TABLE";
3459 foreach(lcmd,
stmt->cmds)
3476 skipValidation =
false;
3484 newcmds =
lappend(newcmds, cmd);
3497 skipValidation =
false;
3500 elog(
ERROR,
"unrecognized node type: %d",
3527 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3528 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
3546 newcmds =
lappend(newcmds, cmd);
3563 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3564 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
3572 newcmds =
lappend(newcmds, cmd);
3596 if (strcmp(def->
defname,
"generated") == 0)
3597 newdef =
lappend(newdef, def);
3599 newseqopts =
lappend(newseqopts, def);
3605 (
errcode(ERRCODE_UNDEFINED_COLUMN),
3606 errmsg(
"column \"%s\" of relation \"%s\" does not exist",
3618 seqstmt->
options = newseqopts;
3634 newcmds =
lappend(newcmds, cmd);
3648 newcmds =
lappend(newcmds, cmd);
3658 newcmds =
lappend(newcmds, cmd);
3667 save_alist = cxt.
alist;
3681 foreach(l, cxt.
alist)
3697 newcmd->
def = (
Node *) idxstmt;
3698 newcmds =
lappend(newcmds, newcmd);
3717 newcmds =
lappend(newcmds, newcmd);
3724 newcmds =
lappend(newcmds, newcmd);
3731 newcmds =
lappend(newcmds, newcmd);
3743 stmt->cmds = newcmds;
3745 *beforeStmts = cxt.
blist;
3765 bool saw_deferrability =
false;
3766 bool saw_initially =
false;
3769 #define SUPPORTS_ATTRS(node) \
3770 ((node) != NULL && \
3771 ((node)->contype == CONSTR_PRIMARY || \
3772 (node)->contype == CONSTR_UNIQUE || \
3773 (node)->contype == CONSTR_EXCLUSION || \
3774 (node)->contype == CONSTR_FOREIGN))
3776 foreach(clist, constraintList)
3781 elog(
ERROR,
"unrecognized node type: %d",
3788 (
errcode(ERRCODE_SYNTAX_ERROR),
3789 errmsg(
"misplaced DEFERRABLE clause"),
3791 if (saw_deferrability)
3793 (
errcode(ERRCODE_SYNTAX_ERROR),
3794 errmsg(
"multiple DEFERRABLE/NOT DEFERRABLE clauses not allowed"),
3796 saw_deferrability =
true;
3803 (
errcode(ERRCODE_SYNTAX_ERROR),
3804 errmsg(
"misplaced NOT DEFERRABLE clause"),
3806 if (saw_deferrability)
3808 (
errcode(ERRCODE_SYNTAX_ERROR),
3809 errmsg(
"multiple DEFERRABLE/NOT DEFERRABLE clauses not allowed"),
3811 saw_deferrability =
true;
3813 if (saw_initially &&
3816 (
errcode(ERRCODE_SYNTAX_ERROR),
3817 errmsg(
"constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3824 (
errcode(ERRCODE_SYNTAX_ERROR),
3825 errmsg(
"misplaced INITIALLY DEFERRED clause"),
3829 (
errcode(ERRCODE_SYNTAX_ERROR),
3830 errmsg(
"multiple INITIALLY IMMEDIATE/DEFERRED clauses not allowed"),
3832 saw_initially =
true;
3838 if (!saw_deferrability)
3842 (
errcode(ERRCODE_SYNTAX_ERROR),
3843 errmsg(
"constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
3850 (
errcode(ERRCODE_SYNTAX_ERROR),
3851 errmsg(
"misplaced INITIALLY IMMEDIATE clause"),
3855 (
errcode(ERRCODE_SYNTAX_ERROR),
3856 errmsg(
"multiple INITIALLY IMMEDIATE/DEFERRED clauses not allowed"),
3858 saw_initially =
true;
3864 lastprimarycon = con;
3866 saw_deferrability =
false;
3867 saw_initially =
false;
3895 (
errcode(ERRCODE_DATATYPE_MISMATCH),
3896 errmsg(
"collations are not supported by type %s",
3952 foreach(elements, schemaElts)
3958 case T_CreateSeqStmt:
4002 case T_CreateTrigStmt:
4016 elog(
ERROR,
"unrecognized node type: %d",
4039 if (*stmt_schema_name == NULL)
4040 *stmt_schema_name =
unconstify(
char *, context_schema);
4041 else if (strcmp(context_schema, *stmt_schema_name) != 0)
4043 (
errcode(ERRCODE_INVALID_SCHEMA_DEFINITION),
4044 errmsg(
"CREATE specifies a schema (%s) "
4045 "different from the one being created (%s)",
4046 *stmt_schema_name, context_schema)));
4061 switch (parentRel->
rd_rel->relkind)
4063 case RELKIND_PARTITIONED_TABLE:
4066 if (cmd->
bound != NULL)
4070 case RELKIND_PARTITIONED_INDEX:
4076 if (cmd->
bound != NULL)
4078 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4079 errmsg(
"\"%s\" is not a partitioned table",
4082 case RELKIND_RELATION:
4085 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4086 errmsg(
"table \"%s\" is not partitioned",
4092 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4093 errmsg(
"index \"%s\" is not partitioned",
4098 elog(
ERROR,
"\"%s\" is not a partitioned table or index",
4132 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4133 errmsg(
"a hash-partitioned table may not have a default partition")));
4149 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4150 errmsg(
"invalid bound specification for a hash partition"),
4153 if (spec->modulus <= 0)
4155 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4156 errmsg(
"modulus for hash partition must be an integer value greater than zero")));
4158 Assert(spec->remainder >= 0);
4160 if (spec->remainder >= spec->modulus)
4162 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4163 errmsg(
"remainder for hash partition must be less than modulus")));
4175 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4176 errmsg(
"invalid bound specification for a list partition"),
4180 if (
key->partattrs[0] != 0)
4182 key->partattrs[0],
false);
4194 foreach(cell, spec->listdatums)
4202 colname, coltype, coltypmod,
4228 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4229 errmsg(
"invalid bound specification for a range partition"),
4234 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4235 errmsg(
"FROM must specify exactly one value per partitioning column")));
4238 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
4239 errmsg(
"TO must specify exactly one value per partitioning column")));
4253 elog(
ERROR,
"unexpected partition strategy: %d", (
int) strategy);
4306 else if (strcmp(
"minvalue",
cname) == 0)
4312 else if (strcmp(
"maxvalue",
cname) == 0)
4329 if (
key->partattrs[
i] != 0)
4331 key->partattrs[
i],
false);
4350 if (
value->constisnull)
4352 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4353 errmsg(
"cannot specify NULL in range bound")));
4362 result =
lappend(result, prd);
4390 if (kind == prd->
kind)
4401 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4402 errmsg(
"every bound following MAXVALUE must also be MAXVALUE"),
4408 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4409 errmsg(
"every bound following MINVALUE must also be MINVALUE"),
4421 const char *colName,
Oid colType,
int32 colTypmod,
4451 (
errcode(ERRCODE_DATATYPE_MISMATCH),
4452 errmsg(
"specified value cannot be cast to type %s for column \"%s\"",
4467 elog(
ERROR,
"could not evaluate partition bound expression");
4477 ((
Const *)
value)->constcollid = partCollation;
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
Oid get_index_am_oid(const char *amname, bool missing_ok)
#define DatumGetArrayTypeP(X)
void deconstruct_array_builtin(ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
AttrMap * build_attrmap_by_name(TupleDesc indesc, TupleDesc outdesc, bool missing_ok)
#define AttributeNumberIsValid(attributeNumber)
#define InvalidAttrNumber
char * get_tablespace_name(Oid spc_oid)
int bms_next_member(const Bitmapset *a, int prevbit)
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_add_member(Bitmapset *a, int x)
#define TextDatumGetCString(d)
#define unconstify(underlying_type, expr)
#define InvalidSubTransactionId
#define OidIsValid(objectId)
Expr * evaluate_expr(Expr *expr, Oid result_type, int32 result_typmod, Oid result_collation)
elog(ERROR, "%s: %s", p2, msg)
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)
Assert(fmt[strlen(fmt) - 1] !='\n')
List * lappend(List *list, void *datum)
List * list_copy(const List *oldlist)
List * list_delete_nth_cell(List *list, int n)
void list_free(List *list)
List * list_concat(List *list1, const List *list2)
List * lcons(void *datum, List *list)
#define AccessExclusiveLock
AttrNumber get_attnum(Oid relid, const char *attname)
char * get_namespace_name(Oid nspid)
Datum get_attoptions(Oid relid, int16 attnum)
Oid get_rel_namespace(Oid relid)
Oid get_typcollation(Oid typid)
char * get_rel_name(Oid relid)
Oid get_atttype(Oid relid, AttrNumber attnum)
Oid get_relname_relid(const char *relname, Oid relnamespace)
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
Alias * makeAlias(const char *aliasname, List *colnames)
RangeVar * makeRangeVar(char *schemaname, char *relname, int location)
FromExpr * makeFromExpr(List *fromlist, Node *quals)
DefElem * makeDefElem(char *name, Node *arg, int location)
ColumnDef * makeColumnDef(const char *colname, Oid typeOid, int32 typmod, Oid collOid)
TypeName * makeTypeNameFromOid(Oid typeOid, int32 typmod)
FuncCall * makeFuncCall(List *name, List *args, CoercionForm funcformat, int location)
char * pstrdup(const char *in)
void pfree(void *pointer)
Oid RangeVarGetAndCheckCreationNamespace(RangeVar *relation, LOCKMODE lockmode, Oid *existing_relation_id)
void RangeVarAdjustRelationPersistence(RangeVar *newRelation, Oid nspid)
Oid RangeVarGetCreationNamespace(const RangeVar *newRelation)
RangeVar * makeRangeVarFromNameList(const List *names)
Oid exprType(const Node *expr)
int exprLocation(const Node *expr)
#define IsA(nodeptr, _type_)
#define castNode(_type_, nodeptr)
ObjectType get_relkind_objtype(char relkind)
#define ObjectAddressSet(addr, class_id, object_id)
char * nodeToString(const void *obj)
Node * transformWhereClause(ParseState *pstate, Node *clause, ParseExprKind exprKind, const char *constructName)
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
void assign_expr_collations(ParseState *pstate, Node *expr)
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
void cancel_parser_errposition_callback(ParseCallbackState *pcbstate)
void free_parsestate(ParseState *pstate)
int parser_errposition(ParseState *pstate, int location)
void setup_parser_errposition_callback(ParseCallbackState *pcbstate, ParseState *pstate, int location)
ParseState * make_parsestate(ParseState *parentParseState)
@ EXPR_KIND_STATS_EXPRESSION
@ EXPR_KIND_INDEX_EXPRESSION
@ EXPR_KIND_PARTITION_BOUND
@ EXPR_KIND_INDEX_PREDICATE
@ EXPR_KIND_ALTER_COL_TRANSFORM
ParseNamespaceItem * addRangeTableEntryForRelation(ParseState *pstate, Relation rel, int lockmode, Alias *alias, bool inh, bool inFromCl)
void addNSItemToQuery(ParseState *pstate, ParseNamespaceItem *nsitem, bool addToJoinList, bool addToRelNameSpace, bool addToVarNameSpace)
char * FigureIndexColname(Node *node)
Oid LookupCollation(ParseState *pstate, List *collnames, int location)
Type typenameType(ParseState *pstate, const TypeName *typeName, int32 *typmod_p)
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
static void generateSerialExtraStmts(CreateStmtContext *cxt, ColumnDef *column, Oid seqtypid, List *seqoptions, bool for_identity, bool col_exists, char **snamespace_p, char **sname_p)
List * transformCreateStmt(CreateStmt *stmt, const char *queryString)
IndexStmt * generateClonedIndexStmt(RangeVar *heapRel, Relation source_idx, const AttrMap *attmap, Oid *constraintOid)
static void transformColumnType(CreateStmtContext *cxt, ColumnDef *column)
static void transformColumnDefinition(CreateStmtContext *cxt, ColumnDef *column)
List * transformCreateSchemaStmtElements(List *schemaElts, const char *schemaName)
CreateStatsStmt * transformStatsStmt(Oid relid, CreateStatsStmt *stmt, const char *queryString)
void transformRuleStmt(RuleStmt *stmt, const char *queryString, List **actions, Node **whereClause)
static void transformIndexConstraints(CreateStmtContext *cxt)
static List * get_collation(Oid collation, Oid actual_datatype)
static IndexStmt * transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
AlterTableStmt * transformAlterTableStmt(Oid relid, AlterTableStmt *stmt, const char *queryString, List **beforeStmts, List **afterStmts)
List * expandTableLikeClause(RangeVar *heapRel, TableLikeClause *table_like_clause)
static void transformTableLikeClause(CreateStmtContext *cxt, TableLikeClause *table_like_clause)
static void transformExtendedStatistics(CreateStmtContext *cxt)
static void transformConstraintAttrs(CreateStmtContext *cxt, List *constraintList)
static void transformTableConstraint(CreateStmtContext *cxt, Constraint *constraint)
static List * get_opclass(Oid opclass, Oid actual_datatype)
IndexStmt * transformIndexStmt(Oid relid, IndexStmt *stmt, const char *queryString)
static List * transformPartitionRangeBounds(ParseState *pstate, List *blist, Relation parent)
static CreateStatsStmt * generateClonedExtStatsStmt(RangeVar *heapRel, Oid heapRelid, Oid source_statsid)
static void transformPartitionCmd(CreateStmtContext *cxt, PartitionCmd *cmd)
static void setSchemaName(const char *context_schema, char **stmt_schema_name)
static void validateInfiniteBounds(ParseState *pstate, List *blist)
static Const * transformPartitionBoundValue(ParseState *pstate, Node *val, const char *colName, Oid colType, int32 colTypmod, Oid partCollation)
static void transformCheckConstraints(CreateStmtContext *cxt, bool skipValidation)
static void transformOfType(CreateStmtContext *cxt, TypeName *ofTypename)
PartitionBoundSpec * transformPartitionBound(ParseState *pstate, Relation parent, PartitionBoundSpec *spec)
static void transformFKConstraints(CreateStmtContext *cxt, bool skipValidation, bool isAddConstraint)
#define SUPPORTS_ATTRS(node)
@ PARTITION_STRATEGY_HASH
@ PARTITION_STRATEGY_LIST
@ PARTITION_STRATEGY_RANGE
@ CONSTR_ATTR_NOT_DEFERRABLE
@ PARTITION_RANGE_DATUM_MAXVALUE
@ PARTITION_RANGE_DATUM_VALUE
@ PARTITION_RANGE_DATUM_MINVALUE
@ AT_AlterColumnGenericOptions
@ CREATE_TABLE_LIKE_COMMENTS
@ CREATE_TABLE_LIKE_GENERATED
@ CREATE_TABLE_LIKE_IDENTITY
@ CREATE_TABLE_LIKE_COMPRESSION
@ CREATE_TABLE_LIKE_STORAGE
@ CREATE_TABLE_LIKE_INDEXES
@ CREATE_TABLE_LIKE_DEFAULTS
@ CREATE_TABLE_LIKE_STATISTICS
@ CREATE_TABLE_LIKE_CONSTRAINTS
Query * transformStmt(ParseState *pstate, Node *parseTree)
TypeName * SystemTypeName(char *name)
List * SystemFuncName(char *name)
PartitionKey RelationGetPartitionKey(Relation rel)
static int get_partition_strategy(PartitionKey key)
static int32 get_partition_col_typmod(PartitionKey key, int col)
static int get_partition_natts(PartitionKey key)
static Oid get_partition_col_typid(PartitionKey key, int col)
static Oid get_partition_col_collation(PartitionKey key, int col)
static List * get_partition_exprs(PartitionKey key)
FormData_pg_am * Form_pg_am
FormData_pg_attribute * Form_pg_attribute
int errdetail_relkind_not_supported(char relkind)
FormData_pg_class * Form_pg_class
FormData_pg_collation * Form_pg_collation
List * RelationGetNotNullConstraints(Oid relid, bool cooked)
Oid get_relation_constraint_oid(Oid relid, const char *conname, bool missing_ok)
FormData_pg_constraint * Form_pg_constraint
void checkMembershipInCurrentExtension(const ObjectAddress *object)
Oid get_index_constraint(Oid indexId)
Oid getIdentitySequence(Oid relid, AttrNumber attnum, bool missing_ok)
FormData_pg_index * Form_pg_index
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define linitial_node(type, l)
#define lsecond_node(type, l)
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)
#define foreach_current_index(cell)
FormData_pg_opclass * Form_pg_opclass
FormData_pg_operator * Form_pg_operator
FormData_pg_statistic_ext * Form_pg_statistic_ext
FormData_pg_type * Form_pg_type
Expr * expression_planner(Expr *expr)
static Oid DatumGetObjectId(Datum X)
static Datum ObjectIdGetDatum(Oid X)
static Pointer DatumGetPointer(Datum X)
void * stringToNode(const char *str)
static chr element(struct vars *v, const chr *startp, const chr *endp)
#define RelationGetRelid(relation)
#define RelationGetDescr(relation)
#define RelationGetRelationName(relation)
#define RelationGetNamespace(relation)
List * RelationGetIndexList(Relation relation)
List * RelationGetIndexPredicate(Relation relation)
List * RelationGetStatExtList(Relation relation)
Bitmapset * RelationGetIndexAttrBitmap(Relation relation, IndexAttrBitmapKind attrKind)
List * RelationGetIndexExpressions(Relation relation)
@ INDEX_ATTR_BITMAP_PRIMARY_KEY
List * untransformRelOptions(Datum options)
#define InvalidRelFileNumber
Node * map_variable_attnos(Node *node, int target_varno, int sublevels_up, const AttrMap *attno_map, Oid to_rowtype, bool *found_whole_row)
Query * getInsertSelectQuery(Query *parsetree, Query ***subquery_ptr)
bool rangeTableEntry_used(Node *node, int rt_index, int sublevels_up)
char * deparse_expression(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit)
List * deparse_context_for(const char *aliasname, Oid relid)
char * quote_qualified_identifier(const char *qualifier, const char *ident)
List * sequence_options(Oid relid)
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