68 #include "utils/fmgroids.h"
100 bool is_validated,
bool is_local,
int inhcount,
101 bool is_no_inherit,
bool is_internal);
105 bool allow_merge,
bool is_local,
109 Node *raw_constraint,
139 false,
'p',
's',
true,
false,
false,
true, 0
145 true,
'p',
'i',
true,
false,
false,
true, 0
151 true,
'p',
'i',
true,
false,
false,
true, 0
157 true,
'p',
'i',
true,
false,
false,
true, 0
163 true,
'p',
'i',
true,
false,
false,
true, 0
169 true,
'p',
'i',
true,
false,
false,
true, 0
181 true,
'p',
'i',
true,
false,
false,
true, 0
194 if (attno >= 0 || attno < -(
int)
lengthof(SysAtt))
195 elog(
ERROR,
"invalid system attribute number %d", attno);
197 elog(
ERROR,
"invalid system attribute number %d", attno);
198 return SysAtt[-attno - 1];
210 for (j = 0; j < (int)
lengthof(SysAtt); j++)
216 if (strcmp(
NameStr(att->attname), attname) == 0)
250 bool shared_relation,
251 bool mapped_relation,
252 bool allow_system_table_mods)
269 if (!allow_system_table_mods &&
274 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
275 errmsg(
"permission denied to create \"%s.%s\"",
277 errdetail(
"System catalog modifications are currently disallowed.")));
288 create_storage =
false;
297 create_storage =
true;
306 create_storage =
true;
316 create_storage =
false;
402 bool allow_system_table_mods)
406 int natts = tupdesc->
natts;
411 (
errcode(ERRCODE_TOO_MANY_COLUMNS),
412 errmsg(
"tables can have at most %d columns",
413 MaxHeapAttributeNumber)));
423 for (i = 0; i < natts; i++)
428 (
errcode(ERRCODE_DUPLICATE_COLUMN),
429 errmsg(
"column name \"%s\" conflicts with a system column name",
437 for (i = 1; i < natts; i++)
439 for (j = 0; j <
i; j++)
444 (
errcode(ERRCODE_DUPLICATE_COLUMN),
445 errmsg(
"column name \"%s\" specified more than once",
453 for (i = 0; i < natts; i++)
456 tupdesc->
attrs[i]->atttypid,
457 tupdesc->
attrs[i]->attcollation,
459 allow_system_table_mods);
480 Oid atttypid,
Oid attcollation,
481 List *containing_rowtypes,
482 bool allow_system_table_mods)
494 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
495 errmsg(
"column \"%s\" has type \"unknown\"", attname),
496 errdetail(
"Proceeding with relation creation anyway.")));
506 if (atttypid !=
ANYARRAYOID || !allow_system_table_mods)
508 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
509 errmsg(
"column \"%s\" has pseudo-type %s",
519 allow_system_table_mods);
538 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
539 errmsg(
"composite type %s cannot be made a member of itself",
542 containing_rowtypes =
lcons_oid(atttypid, containing_rowtypes);
548 for (i = 0; i < tupdesc->
natts; i++)
552 if (attr->attisdropped)
555 attr->atttypid, attr->attcollation,
557 allow_system_table_mods);
571 allow_system_table_mods);
580 (
errcode(ERRCODE_INVALID_TABLE_DEFINITION),
581 errmsg(
"no collation was derived for column \"%s\" with collatable type %s",
583 errhint(
"Use the COLLATE clause to set the collation explicitly.")));
608 memset(values, 0,
sizeof(values));
609 memset(nulls,
false,
sizeof(nulls));
640 if (indstate !=
NULL)
666 int natts = tupdesc->
natts;
681 for (i = 0; i < natts; i++)
685 attr->attrelid = new_rel_oid;
687 attr->attstattarget = -1;
688 attr->attcacheoff = -1;
697 referenced.
objectId = attr->atttypid;
706 referenced.
objectId = attr->attcollation;
719 for (i = 0; i < (int)
lengthof(SysAtt); i++)
731 attStruct.attrelid = new_rel_oid;
736 attStruct.attislocal = oidislocal;
737 attStruct.attinhcount = oidinhcount;
778 memset(values, 0,
sizeof(values));
779 memset(nulls,
false,
sizeof(nulls));
809 if (relacl != (
Datum) 0)
813 if (reloptions != (
Datum) 0)
858 new_rel_reltup = new_rel_desc->
rd_rel;
867 new_rel_reltup->relpages = 0;
868 new_rel_reltup->reltuples = 0;
869 new_rel_reltup->relallvisible = 0;
873 new_rel_reltup->relpages = 1;
874 new_rel_reltup->reltuples = 1;
875 new_rel_reltup->relallvisible = 0;
879 new_rel_reltup->relpages = 0;
880 new_rel_reltup->reltuples = 0;
881 new_rel_reltup->relallvisible = 0;
919 new_rel_reltup->relowner = relowner;
920 new_rel_reltup->reltype = new_type_oid;
921 new_rel_reltup->reloftype = reloftype;
1019 List *cooked_constraints,
1021 char relpersistence,
1022 bool shared_relation,
1023 bool mapped_relation,
1029 bool allow_system_table_mods,
1056 (
errcode(ERRCODE_DUPLICATE_TABLE),
1057 errmsg(
"relation \"%s\" already exists", relname)));
1072 (
errcode(ERRCODE_DUPLICATE_OBJECT),
1073 errmsg(
"type \"%s\" already exists", relname),
1074 errhint(
"A relation has an associated type of the same name, "
1075 "so you must use a name that doesn't conflict "
1076 "with any existing type.")));
1083 elog(
ERROR,
"shared relations must be placed in pg_global tablespace");
1101 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1102 errmsg(
"pg_class heap OID value not set when in binary upgrade mode")));
1161 allow_system_table_mods);
1237 pfree(relarrayname);
1261 oidislocal, oidinhcount);
1293 referenced.
objectId = relnamespace;
1315 nnewmembers =
aclmembers(relacl, &newmembers);
1319 nnewmembers, newmembers);
1428 elog(
ERROR,
"cache lookup failed for relation %u", relid);
1548 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
1563 attStruct->attisdropped =
true;
1577 attStruct->attnotnull =
false;
1580 attStruct->attstattarget = 0;
1585 snprintf(newattname,
sizeof(newattname),
1586 "........pg.dropped.%d........", attnum);
1587 namestrcpy(&(attStruct->attname), newattname);
1646 object.objectSubId = 0;
1657 if (complain && !found)
1658 elog(
ERROR,
"could not find attrdef tuple for relation %u attnum %d",
1695 elog(
ERROR,
"could not find tuple for attrdef %u", attrdefId);
1716 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
1782 elog(
ERROR,
"cache lookup failed for foreign table %u", relid);
1848 Node *expr,
bool is_internal)
1855 static bool nulls[4] = {
false,
false,
false,
false};
1913 elog(
ERROR,
"cache lookup failed for attribute %d of relation %u",
1916 if (!attStruct->atthasdef)
1918 attStruct->atthasdef =
true;
1961 bool is_validated,
bool is_local,
int inhcount,
1962 bool is_no_inherit,
bool is_internal)
2001 foreach(vl, varList)
2006 for (j = 0; j <
i; j++)
2067 if (!cooked_constraints)
2077 foreach(lc, cooked_constraints)
2093 elog(
ERROR,
"unrecognized constraint type: %d",
2130 List *newColDefaults,
2131 List *newConstraints,
2136 List *cookedConstraints =
NIL;
2152 oldconstr = tupleDesc->
constr;
2173 foreach(cell, newColDefaults)
2179 atp->atttypid, atp->atttypmod,
2203 cooked->
expr = expr;
2206 cooked->
inhcount = is_local ? 0 : 1;
2208 cookedConstraints =
lappend(cookedConstraints, cooked);
2214 numchecks = numoldchecks;
2216 foreach(cell, newConstraints)
2256 foreach(cell2, checknames)
2258 if (strcmp((
char *)
lfirst(cell2), ccname) == 0)
2260 (
errcode(ERRCODE_DUPLICATE_OBJECT),
2261 errmsg(
"check constraint \"%s\" already exists",
2266 checknames =
lappend(checknames, ccname);
2275 allow_merge, is_local,
2316 checknames =
lappend(checknames, ccname);
2329 cooked->
name = ccname;
2331 cooked->
expr = expr;
2334 cooked->
inhcount = is_local ? 0 : 1;
2336 cookedConstraints =
lappend(cookedConstraints, cooked);
2348 return cookedConstraints;
2363 bool allow_merge,
bool is_local,
2404 conDesc->
rd_att, &isnull);
2411 if (!found || !allow_merge)
2413 (
errcode(ERRCODE_DUPLICATE_OBJECT),
2414 errmsg(
"constraint \"%s\" for relation \"%s\" already exists",
2421 if (con->connoinherit)
2423 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2424 errmsg(
"constraint \"%s\" conflicts with non-inherited constraint on relation \"%s\"",
2428 con->conislocal =
true;
2434 con->connoinherit =
true;
2438 (
errmsg(
"merging constraint \"%s\" with inherited definition",
2473 elog(
ERROR,
"cache lookup failed for relation %u",
2477 if (relStruct->relchecks != numchecks)
2479 relStruct->relchecks = numchecks;
2530 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
2531 errmsg(
"cannot use column references in default expression")));
2541 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2542 errmsg(
"default expression must not return a set")));
2554 atttypid, atttypmod,
2560 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2561 errmsg(
"column \"%s\" is of type %s"
2562 " but default expression is of type %s",
2566 errhint(
"You will need to rewrite or cast the expression.")));
2586 Node *raw_constraint,
2612 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
2613 errmsg(
"only table \"%s\" can be referenced in check constraint",
2698 index_build(heapRelation, currentIndex, indexInfo,
false,
true);
2721 foreach(cell, relids)
2727 relations =
lappend(relations, rel);
2734 foreach(cell, relations)
2767 toastrelid = rel->
rd_rel->reltoastrelid;
2805 foreach(cell, relations)
2809 if (rel->
rd_rel->relhastriggers)
2824 if (dependents ==
NIL)
2841 foreach(cell2, dependents)
2852 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2853 errmsg(
"unsupported ON COMMIT and foreign key combination"),
2854 errdetail(
"Table \"%s\" references \"%s\", but they do not have the same ON COMMIT setting.",
2855 relname2, relname)));
2858 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2859 errmsg(
"cannot truncate a table referenced in a foreign key constraint"),
2860 errdetail(
"Table \"%s\" references \"%s\".",
2862 errhint(
"Truncate table \"%s\" at the same time, "
2863 "or use TRUNCATE ... CASCADE.",