69#include "utils/fmgroids.h"
114 Oid rangeOid,
Oid subtype);
116 Oid multirangeOid,
Oid rangeOid,
117 Oid rangeArrayOid,
Oid *castFuncOid);
156 int16 internalLength = -1;
165 char category = TYPCATEGORY_USER;
166 bool preferred =
false;
169 char *defaultValue = NULL;
170 bool byValue =
false;
171 char alignment = TYPALIGN_INT;
172 char storage = TYPSTORAGE_PLAIN;
175 DefElem *internalLengthEl = NULL;
180 DefElem *typmodinNameEl = NULL;
181 DefElem *typmodoutNameEl = NULL;
183 DefElem *subscriptNameEl = NULL;
188 DefElem *defaultValueEl = NULL;
220 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
221 errmsg(
"must be superuser to create a base type")));
253 errmsg(
"type \"%s\" already exists", typeName)));
260 if (parameters ==
NIL)
265 errmsg(
"type \"%s\" already exists", typeName)));
278 errmsg(
"type \"%s\" does not exist", typeName),
279 errhint(
"Create the type as a shell type, then create its I/O functions, then do a full CREATE TYPE.")));
282 foreach(pl, parameters)
287 if (strcmp(defel->
defname,
"like") == 0)
288 defelp = &likeTypeEl;
289 else if (strcmp(defel->
defname,
"internallength") == 0)
290 defelp = &internalLengthEl;
291 else if (strcmp(defel->
defname,
"input") == 0)
292 defelp = &inputNameEl;
293 else if (strcmp(defel->
defname,
"output") == 0)
294 defelp = &outputNameEl;
295 else if (strcmp(defel->
defname,
"receive") == 0)
296 defelp = &receiveNameEl;
297 else if (strcmp(defel->
defname,
"send") == 0)
298 defelp = &sendNameEl;
299 else if (strcmp(defel->
defname,
"typmod_in") == 0)
300 defelp = &typmodinNameEl;
301 else if (strcmp(defel->
defname,
"typmod_out") == 0)
302 defelp = &typmodoutNameEl;
303 else if (strcmp(defel->
defname,
"analyze") == 0 ||
304 strcmp(defel->
defname,
"analyse") == 0)
305 defelp = &analyzeNameEl;
306 else if (strcmp(defel->
defname,
"subscript") == 0)
307 defelp = &subscriptNameEl;
308 else if (strcmp(defel->
defname,
"category") == 0)
309 defelp = &categoryEl;
310 else if (strcmp(defel->
defname,
"preferred") == 0)
311 defelp = &preferredEl;
312 else if (strcmp(defel->
defname,
"delimiter") == 0)
313 defelp = &delimiterEl;
314 else if (strcmp(defel->
defname,
"element") == 0)
315 defelp = &elemTypeEl;
316 else if (strcmp(defel->
defname,
"default") == 0)
317 defelp = &defaultValueEl;
318 else if (strcmp(defel->
defname,
"passedbyvalue") == 0)
320 else if (strcmp(defel->
defname,
"alignment") == 0)
321 defelp = &alignmentEl;
322 else if (strcmp(defel->
defname,
"storage") == 0)
324 else if (strcmp(defel->
defname,
"collatable") == 0)
325 defelp = &collatableEl;
330 (
errcode(ERRCODE_SYNTAX_ERROR),
331 errmsg(
"type attribute \"%s\" not recognized",
353 internalLength = likeForm->typlen;
354 byValue = likeForm->typbyval;
355 alignment = likeForm->typalign;
356 storage = likeForm->typstorage;
359 if (internalLengthEl)
383 if (category < 32 || category > 126)
385 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
386 errmsg(
"invalid type category \"%s\": must be simple ASCII",
404 (
errcode(ERRCODE_DATATYPE_MISMATCH),
405 errmsg(
"array element type cannot be %s",
424 alignment = TYPALIGN_DOUBLE;
427 alignment = TYPALIGN_INT;
430 alignment = TYPALIGN_SHORT;
433 alignment = TYPALIGN_CHAR;
436 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
437 errmsg(
"alignment \"%s\" not recognized",
a)));
453 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
454 errmsg(
"storage \"%s\" not recognized",
a)));
462 if (inputName ==
NIL)
464 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
465 errmsg(
"type input function must be specified")));
466 if (outputName ==
NIL)
468 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
469 errmsg(
"type output function must be specified")));
471 if (typmodinName ==
NIL && typmodoutName !=
NIL)
473 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
474 errmsg(
"type modifier output function is useless without a type modifier input function")));
511 if (internalLength > 0 && !byValue &&
get_typlen(elemType) > 0)
512 subscriptOid = F_RAW_ARRAY_SUBSCRIPT_HANDLER;
515 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
516 errmsg(
"element type cannot be specified without a subscripting function")));
613 alignment = (alignment == TYPALIGN_DOUBLE) ? TYPALIGN_DOUBLE : TYPALIGN_INT;
633 F_ARRAY_SUBSCRIPT_HANDLER,
666 elog(
ERROR,
"cache lookup failed for type %u", typeOid);
700 char *domainArrayName;
703 int16 internalLength;
706 Oid receiveProcedure;
708 Oid analyzeProcedure;
717 char *defaultValue = NULL;
718 char *defaultValueBin = NULL;
719 bool saw_default =
false;
720 bool typNotNull =
false;
721 bool nullDefined =
false;
758 errmsg(
"type \"%s\" already exists", domainName)));
766 basetypeoid = baseType->oid;
776 typtype = baseType->typtype;
777 if (typtype != TYPTYPE_BASE &&
778 typtype != TYPTYPE_COMPOSITE &&
779 typtype != TYPTYPE_DOMAIN &&
780 typtype != TYPTYPE_ENUM &&
781 typtype != TYPTYPE_RANGE &&
782 typtype != TYPTYPE_MULTIRANGE)
784 (
errcode(ERRCODE_DATATYPE_MISMATCH),
785 errmsg(
"\"%s\" is not a valid base type for a domain",
802 baseColl = baseType->typcollation;
803 if (
stmt->collClause)
806 domaincoll = baseColl;
811 (
errcode(ERRCODE_DATATYPE_MISMATCH),
812 errmsg(
"collations are not supported by type %s",
817 byValue = baseType->typbyval;
820 alignment = baseType->typalign;
823 storage = baseType->typstorage;
826 internalLength = baseType->typlen;
829 category = baseType->typcategory;
832 delimiter = baseType->typdelim;
835 inputProcedure = F_DOMAIN_IN;
836 outputProcedure = baseType->typoutput;
837 receiveProcedure = F_DOMAIN_RECV;
838 sendProcedure = baseType->typsend;
843 analyzeProcedure = baseType->typanalyze;
853 Anum_pg_type_typdefault, &isnull);
859 Anum_pg_type_typdefaultbin, &isnull);
867 foreach(listptr, schema)
872 elog(
ERROR,
"unrecognized node type: %d",
885 errmsg(
"multiple default expressions"),
913 if (defaultExpr == NULL ||
915 ((
Const *) defaultExpr)->constisnull))
918 defaultValueBin = NULL;
937 defaultValueBin = NULL;
942 if (nullDefined && !typNotNull)
945 errmsg(
"conflicting NULL/NOT NULL constraints"),
949 errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
950 errmsg(
"not-null constraints for domains cannot be marked NO INHERIT"),
957 if (nullDefined && typNotNull)
960 errmsg(
"conflicting NULL/NOT NULL constraints"),
976 errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
977 errmsg(
"check constraints for domains cannot be marked NO INHERIT"),
988 errmsg(
"unique constraints not possible for domains"),
994 (
errcode(ERRCODE_SYNTAX_ERROR),
995 errmsg(
"primary key constraints not possible for domains"),
1001 (
errcode(ERRCODE_SYNTAX_ERROR),
1002 errmsg(
"exclusion constraints not possible for domains"),
1008 (
errcode(ERRCODE_SYNTAX_ERROR),
1009 errmsg(
"foreign key constraints not possible for domains"),
1018 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1019 errmsg(
"specifying constraint deferrability not supported for domains"),
1026 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1027 errmsg(
"specifying GENERATED not supported for domains"),
1034 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1035 errmsg(
"specifying constraint enforceability not supported for domains"),
1089 alignment = (alignment == TYPALIGN_DOUBLE) ? TYPALIGN_DOUBLE : TYPALIGN_INT;
1109 F_ARRAY_SUBSCRIPT_HANDLER,
1118 TYPSTORAGE_EXTENDED,
1124 pfree(domainArrayName);
1129 foreach(listptr, schema)
1139 basetypeoid, basetypeMod,
1140 constr, domainName, NULL);
1145 basetypeoid, basetypeMod,
1146 constr, domainName, NULL);
1176 char *enumArrayName;
1205 errmsg(
"type \"%s\" already exists", enumName)));
1272 F_ARRAY_SUBSCRIPT_HANDLER,
1281 TYPSTORAGE_EXTENDED,
1287 pfree(enumArrayName);
1289 return enumTypeAddr;
1310 elog(
ERROR,
"cache lookup failed for type %u", enum_type_oid);
1326 stmt->newValNeighbor,
stmt->newValIsAfter,
1327 stmt->skipIfNewValExists);
1350 if (typTup->typtype != TYPTYPE_ENUM)
1352 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1353 errmsg(
"%s is not an enum",
1377 char *rangeArrayName;
1378 char *multirangeTypeName = NULL;
1379 char *multirangeArrayName;
1383 Oid multirangeArrayOid;
1385 List *rangeSubOpclassName =
NIL;
1386 List *rangeCollationName =
NIL;
1387 List *rangeCanonicalName =
NIL;
1388 List *rangeSubtypeDiffName =
NIL;
1389 Oid rangeSubOpclass;
1431 errmsg(
"type \"%s\" already exists", typeName)));
1440 foreach(lc,
stmt->params)
1444 if (strcmp(defel->
defname,
"subtype") == 0)
1451 else if (strcmp(defel->
defname,
"subtype_opclass") == 0)
1453 if (rangeSubOpclassName !=
NIL)
1457 else if (strcmp(defel->
defname,
"collation") == 0)
1459 if (rangeCollationName !=
NIL)
1463 else if (strcmp(defel->
defname,
"canonical") == 0)
1465 if (rangeCanonicalName !=
NIL)
1469 else if (strcmp(defel->
defname,
"subtype_diff") == 0)
1471 if (rangeSubtypeDiffName !=
NIL)
1475 else if (strcmp(defel->
defname,
"multirange_type_name") == 0)
1477 if (multirangeTypeName != NULL)
1481 &multirangeTypeName);
1485 (
errcode(ERRCODE_SYNTAX_ERROR),
1486 errmsg(
"type attribute \"%s\" not recognized",
1493 (
errcode(ERRCODE_SYNTAX_ERROR),
1494 errmsg(
"type attribute \"subtype\" is required")));
1498 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1499 errmsg(
"range subtype cannot be %s",
1508 if (rangeCollationName !=
NIL)
1515 if (rangeCollationName !=
NIL)
1517 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1518 errmsg(
"range collation specified but subtype does not support collation")));
1523 if (rangeCanonicalName !=
NIL)
1527 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1528 errmsg(
"cannot specify a canonical function without a pre-created shell type"),
1529 errhint(
"Create the type as a shell type, then create its canonicalization function, then do a full CREATE TYPE.")));
1536 if (rangeSubtypeDiffName !=
NIL)
1543 &subtyplen, &subtypbyval, &subtypalign);
1546 alignment = (subtypalign == TYPALIGN_DOUBLE) ? TYPALIGN_DOUBLE : TYPALIGN_INT;
1582 TYPSTORAGE_EXTENDED,
1591 if (multirangeTypeName)
1611 errmsg(
"type \"%s\" already exists", multirangeTypeName)));
1617 multirangeNamespace = typeNamespace;
1624 multirangeNamespace,
1639 F_MULTIRANGE_TYPANALYZE,
1654 Assert(multirangeOid == mltrngaddress.objectId);
1657 RangeCreate(typoid, rangeSubtype, rangeCollation, rangeSubOpclass,
1658 rangeCanonical, rangeSubtypeDiff, multirangeOid);
1683 F_ARRAY_SUBSCRIPT_HANDLER,
1692 TYPSTORAGE_EXTENDED,
1698 pfree(rangeArrayName);
1705 multirangeArrayName,
1706 multirangeNamespace,
1722 F_ARRAY_SUBSCRIPT_HANDLER,
1740 multirangeOid, typoid, rangeArrayOid,
1745 COERCION_CODE_EXPLICIT, COERCION_METHOD_FUNCTION,
1748 pfree(multirangeArrayName);
1764 Oid rangeOid,
Oid subtype)
1766 static const char *
const prosrc[2] = {
"range_constructor2",
1767 "range_constructor3"};
1768 static const int pronargs[2] = {2, 3};
1770 Oid constructorArgTypes[3];
1775 constructorArgTypes[0] = subtype;
1776 constructorArgTypes[1] = subtype;
1777 constructorArgTypes[2] = TEXTOID;
1779 referenced.
classId = TypeRelationId;
1795 BOOTSTRAP_SUPERUSERID,
1797 F_FMGR_INTERNAL_VALIDATOR,
1805 PROVOLATILE_IMMUTABLE,
1807 constructorArgTypesVector,
1838 Oid multirangeOid,
Oid rangeOid,
Oid rangeArrayOid,
1844 Datum allParamTypes;
1849 referenced.
classId = TypeRelationId;
1850 referenced.
objectId = multirangeOid;
1860 BOOTSTRAP_SUPERUSERID,
1862 F_FMGR_INTERNAL_VALIDATOR,
1863 "multirange_constructor0",
1870 PROVOLATILE_IMMUTABLE,
1904 BOOTSTRAP_SUPERUSERID,
1906 F_FMGR_INTERNAL_VALIDATOR,
1907 "multirange_constructor1",
1914 PROVOLATILE_IMMUTABLE,
1942 BOOTSTRAP_SUPERUSERID,
1944 F_FMGR_INTERNAL_VALIDATOR,
1945 "multirange_constructor2",
1952 PROVOLATILE_IMMUTABLE,
1967 pfree(allParameterTypes);
1968 pfree(parameterModes);
1990 argList[0] = CSTRINGOID;
1991 argList[1] = OIDOID;
1992 argList[2] = INT4OID;
2000 (
errcode(ERRCODE_AMBIGUOUS_FUNCTION),
2001 errmsg(
"type input function %s has multiple matches",
2010 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
2011 errmsg(
"function %s does not exist",
2018 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2019 errmsg(
"type input function %s must return type %s",
2034 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2035 errmsg(
"type input function %s should not be volatile",
2051 argList[0] = typeOid;
2056 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
2057 errmsg(
"function %s does not exist",
2062 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2063 errmsg(
"type output function %s must return type %s",
2069 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2070 errmsg(
"type output function %s should not be volatile",
2088 argList[0] = INTERNALOID;
2089 argList[1] = OIDOID;
2090 argList[2] = INT4OID;
2098 (
errcode(ERRCODE_AMBIGUOUS_FUNCTION),
2099 errmsg(
"type receive function %s has multiple matches",
2108 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
2109 errmsg(
"function %s does not exist",
2116 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2117 errmsg(
"type receive function %s must return type %s",
2123 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2124 errmsg(
"type receive function %s should not be volatile",
2140 argList[0] = typeOid;
2145 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
2146 errmsg(
"function %s does not exist",
2151 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2152 errmsg(
"type send function %s must return type %s",
2158 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2159 errmsg(
"type send function %s should not be volatile",
2174 argList[0] = CSTRINGARRAYOID;
2179 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
2180 errmsg(
"function %s does not exist",
2185 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2186 errmsg(
"typmod_in function %s must return type %s",
2192 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2193 errmsg(
"type modifier input function %s should not be volatile",
2208 argList[0] = INT4OID;
2213 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
2214 errmsg(
"function %s does not exist",
2219 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2220 errmsg(
"typmod_out function %s must return type %s",
2226 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2227 errmsg(
"type modifier output function %s should not be volatile",
2242 argList[0] = INTERNALOID;
2247 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
2248 errmsg(
"function %s does not exist",
2253 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2254 errmsg(
"type analyze function %s must return type %s",
2271 argList[0] = INTERNALOID;
2276 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
2277 errmsg(
"function %s does not exist",
2282 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2283 errmsg(
"type subscripting function %s must return type %s",
2290 if (procOid == F_ARRAY_SUBSCRIPT_HANDLER)
2292 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2293 errmsg(
"user-defined types cannot use subscripting function %s",
2324 (
errcode(ERRCODE_DATATYPE_MISMATCH),
2325 errmsg(
"operator class \"%s\" does not accept data type %s",
2336 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2337 errmsg(
"data type %s has no default operator class for access method \"%s\"",
2339 errhint(
"You must specify an operator class for the range type or define a default operator class for the subtype.")));
2357 argList[0] = typeOid;
2363 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
2364 errmsg(
"function %s does not exist",
2369 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2370 errmsg(
"range canonical function %s must return range type",
2375 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2376 errmsg(
"range canonical function %s must be immutable",
2398 argList[0] = subtype;
2399 argList[1] = subtype;
2405 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
2406 errmsg(
"function %s does not exist",
2411 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2412 errmsg(
"range subtype diff function %s must return type %s",
2414 "double precision")));
2418 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2419 errmsg(
"range subtype diff function %s must be immutable",
2445 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2446 errmsg(
"pg_type array OID value not set when in binary upgrade mode")));
2460 return type_array_oid;
2471 Oid type_multirange_oid;
2478 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2479 errmsg(
"pg_type multirange OID value not set when in binary upgrade mode")));
2493 return type_multirange_oid;
2504 Oid type_multirange_array_oid;
2511 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2512 errmsg(
"pg_type multirange array OID value not set when in binary upgrade mode")));
2526 return type_multirange_array_oid;
2610 Node *defaultExpr = NULL;
2611 Datum new_record[Natts_pg_type] = {0};
2612 bool new_record_nulls[Natts_pg_type] = {0};
2613 bool new_record_repl[Natts_pg_type] = {0};
2627 elog(
ERROR,
"cache lookup failed for type %u", domainoid);
2646 typTup->typbasetype,
2656 if (defaultExpr == NULL ||
2657 (
IsA(defaultExpr,
Const) && ((
Const *) defaultExpr)->constisnull))
2661 new_record_nulls[Anum_pg_type_typdefaultbin - 1] =
true;
2662 new_record_repl[Anum_pg_type_typdefaultbin - 1] =
true;
2663 new_record_nulls[Anum_pg_type_typdefault - 1] =
true;
2664 new_record_repl[Anum_pg_type_typdefault - 1] =
true;
2681 new_record_repl[Anum_pg_type_typdefaultbin - 1] =
true;
2683 new_record_repl[Anum_pg_type_typdefault - 1] =
true;
2689 new_record_nulls[Anum_pg_type_typdefaultbin - 1] =
true;
2690 new_record_repl[Anum_pg_type_typdefaultbin - 1] =
true;
2691 new_record_nulls[Anum_pg_type_typdefault - 1] =
true;
2692 new_record_repl[Anum_pg_type_typdefault - 1] =
true;
2696 new_record, new_record_nulls,
2749 elog(
ERROR,
"cache lookup failed for type %u", domainoid);
2756 if (typTup->typnotnull == notNull)
2772 typTup->typbasetype, typTup->typtypmod,
2773 constr,
NameStr(typTup->typname), NULL);
2784 elog(
ERROR,
"could not find not-null constraint on domain \"%s\"",
NameStr(typTup->typname));
2794 typTup->typnotnull = notNull;
2840 elog(
ERROR,
"cache lookup failed for type %u", domainoid);
2850 Anum_pg_constraint_conrelid,
2854 Anum_pg_constraint_contypid,
2858 Anum_pg_constraint_conname,
2871 if (construct->contype == CONSTRAINT_NOTNULL)
2877 conobj.
classId = ConstraintRelationId;
2893 (
errcode(ERRCODE_UNDEFINED_OBJECT),
2894 errmsg(
"constraint \"%s\" of domain \"%s\" does not exist",
2898 (
errmsg(
"constraint \"%s\" of domain \"%s\" does not exist, skipping",
2944 elog(
ERROR,
"cache lookup failed for type %u", domainoid);
2951 elog(
ERROR,
"unrecognized node type: %d",
2952 (
int)
nodeTag(newConstraint));
2967 typTup->typbasetype, typTup->typtypmod,
2968 constr,
NameStr(typTup->typname), constrAddr);
2990 if (typTup->typnotnull)
2996 typTup->typbasetype, typTup->typtypmod,
2997 constr,
NameStr(typTup->typname), constrAddr);
3002 typTup->typnotnull =
true;
3046 elog(
ERROR,
"cache lookup failed for type %u", domainoid);
3057 Anum_pg_constraint_conrelid,
3061 Anum_pg_constraint_contypid,
3065 Anum_pg_constraint_conname,
3075 (
errcode(ERRCODE_UNDEFINED_OBJECT),
3076 errmsg(
"constraint \"%s\" of domain \"%s\" does not exist",
3080 if (con->contype != CONSTRAINT_CHECK)
3082 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3083 errmsg(
"constraint \"%s\" of domain \"%s\" is not a check constraint",
3096 copy_con->convalidated =
true;
3162 (
errcode(ERRCODE_NOT_NULL_VIOLATION),
3163 errmsg(
"column \"%s\" of table \"%s\" contains null values",
3251 (
errcode(ERRCODE_CHECK_VIOLATION),
3252 errmsg(
"column \"%s\" of table \"%s\" contains values that violate the new constraint",
3325 Anum_pg_depend_refclassid,
3329 Anum_pg_depend_refobjid,
3345 if (pg_depend->classid == TypeRelationId)
3347 if (
get_typtype(pg_depend->objid) == TYPTYPE_DOMAIN)
3375 if (pg_depend->classid != RelationRelationId ||
3376 pg_depend->objsubid <= 0)
3380 foreach(rellist, result)
3416 if (rel->
rd_rel->relkind != RELKIND_RELATION &&
3417 rel->
rd_rel->relkind != RELKIND_MATVIEW)
3428 result =
lappend(result, rtc);
3440 if (pg_att->attisdropped || pg_att->atttypid != domainOid)
3451 while (ptr > 0 && rtc->
atts[ptr - 1] > pg_depend->objsubid)
3453 rtc->
atts[ptr] = rtc->
atts[ptr - 1];
3456 rtc->
atts[ptr] = pg_depend->objsubid;
3478 if (typTup->typtype != TYPTYPE_DOMAIN)
3480 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3481 errmsg(
"%s is not a domain",
3515 errmsg(
"constraint \"%s\" for domain \"%s\" already exists",
3516 constr->
conname, domainName)));
3538 domVal->
typeId = baseTypeOid;
3539 domVal->typeMod = typMod;
3565 (
errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
3566 errmsg(
"cannot use table references in domain check constraint")));
3636 colname =
strVal(field1);
3637 if (strcmp(colname,
"value") == 0)
3643 return (
Node *) domVal;
3671 errmsg(
"constraint \"%s\" for domain \"%s\" already exists",
3672 constr->
conname, domainName)));
3731 const char *newTypeName =
stmt->newname;
3748 elog(
ERROR,
"cache lookup failed for type %u", typeOid);
3758 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3759 errmsg(
"%s is not a domain",
3767 if (typTup->typtype == TYPTYPE_COMPOSITE &&
3770 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3771 errmsg(
"%s is a table's row type",
3778 if (IsTrueArrayType(typTup))
3780 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3781 errmsg(
"cannot alter array type %s",
3783 errhint(
"You can alter type %s, which will alter the array type as well.",
3792 if (typTup->typtype == TYPTYPE_COMPOSITE)
3796 typTup->typnamespace);
3829 (
errcode(ERRCODE_UNDEFINED_OBJECT),
3830 errmsg(
"type \"%s\" does not exist",
3841 if (objecttype ==
OBJECT_DOMAIN && typTup->typtype != TYPTYPE_DOMAIN)
3843 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3844 errmsg(
"%s is not a domain",
3852 if (typTup->typtype == TYPTYPE_COMPOSITE &&
3855 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3856 errmsg(
"%s is a table's row type",
3863 if (IsTrueArrayType(typTup))
3865 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3866 errmsg(
"cannot alter array type %s",
3868 errhint(
"You can alter type %s, which will alter the array type as well.",
3872 if (typTup->typtype == TYPTYPE_MULTIRANGE)
3878 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
3879 errmsg(
"cannot alter multirange type %s",
3882 errhint(
"You can alter type %s, which will alter the multirange type as well.",
3890 if (typTup->typowner != newOwnerId)
3903 aclresult =
object_aclcheck(NamespaceRelationId, typTup->typnamespace,
3944 elog(
ERROR,
"cache lookup failed for type %u", typeOid);
3952 if (typTup->typtype == TYPTYPE_COMPOSITE)
3979 Datum repl_val[Natts_pg_type];
3980 bool repl_null[Natts_pg_type];
3981 bool repl_repl[Natts_pg_type];
3990 elog(
ERROR,
"cache lookup failed for type %u", typeOid);
3993 memset(repl_null,
false,
sizeof(repl_null));
3994 memset(repl_repl,
false,
sizeof(repl_repl));
3996 repl_repl[Anum_pg_type_typowner - 1] =
true;
4000 Anum_pg_type_typacl,
4007 typTup->typowner, newOwnerId);
4008 repl_repl[Anum_pg_type_typacl - 1] =
true;
4022 if (typTup->typtype == TYPTYPE_RANGE)
4028 (
errcode(ERRCODE_UNDEFINED_OBJECT),
4029 errmsg(
"could not find multirange type for data type %s",
4059 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
4060 errmsg(
"%s is not a domain",
4071 *oldschema = oldNspOid;
4104 if (ignoreDependent)
4107 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
4108 errmsg(
"cannot alter array type %s",
4110 errhint(
"You can alter type %s, which will alter the array type as well.",
4144 bool isImplicitArray,
4145 bool ignoreDependent,
4146 bool errorOnTableType,
4160 thisobj.
classId = TypeRelationId;
4171 elog(
ERROR,
"cache lookup failed for type %u", typeOid);
4174 oldNspOid = typform->typnamespace;
4175 arrayOid = typform->typarray;
4178 if (oldNspOid != nspOid)
4189 errmsg(
"type \"%s\" already exists in schema \"%s\"",
4196 (typform->typtype == TYPTYPE_COMPOSITE &&
4202 if (ignoreDependent)
4207 if (errorOnTableType)
4209 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
4210 errmsg(
"%s is a table's row type",
4213 errhint(
"Use %s instead.",
"ALTER TABLE")));
4216 if (oldNspOid != nspOid)
4221 typform->typnamespace = nspOid;
4249 nspOid,
false, objsMoved);
4254 if (typform->typtype == TYPTYPE_DOMAIN)
4263 if (oldNspOid != nspOid &&
4267 NamespaceRelationId, oldNspOid, nspOid) != 1)
4268 elog(
ERROR,
"could not change schema dependency for type \"%s\"",
4307 bool requireSuper =
false;
4321 memset(&atparams, 0,
sizeof(atparams));
4322 foreach(pl,
stmt->options)
4326 if (strcmp(defel->
defname,
"storage") == 0)
4331 atparams.
storage = TYPSTORAGE_PLAIN;
4333 atparams.
storage = TYPSTORAGE_EXTERNAL;
4335 atparams.
storage = TYPSTORAGE_EXTENDED;
4337 atparams.
storage = TYPSTORAGE_MAIN;
4340 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4341 errmsg(
"storage \"%s\" not recognized",
a)));
4347 if (atparams.
storage != TYPSTORAGE_PLAIN && typForm->typlen != -1)
4349 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4350 errmsg(
"fixed-size types must have storage PLAIN")));
4362 if (atparams.
storage != TYPSTORAGE_PLAIN &&
4363 typForm->typstorage == TYPSTORAGE_PLAIN)
4364 requireSuper =
true;
4365 else if (atparams.
storage == TYPSTORAGE_PLAIN &&
4366 typForm->typstorage != TYPSTORAGE_PLAIN)
4368 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4369 errmsg(
"cannot change type's storage to PLAIN")));
4373 else if (strcmp(defel->
defname,
"receive") == 0)
4375 if (defel->
arg != NULL)
4383 requireSuper =
true;
4385 else if (strcmp(defel->
defname,
"send") == 0)
4387 if (defel->
arg != NULL)
4395 requireSuper =
true;
4397 else if (strcmp(defel->
defname,
"typmod_in") == 0)
4399 if (defel->
arg != NULL)
4406 requireSuper =
true;
4408 else if (strcmp(defel->
defname,
"typmod_out") == 0)
4410 if (defel->
arg != NULL)
4417 requireSuper =
true;
4419 else if (strcmp(defel->
defname,
"analyze") == 0)
4421 if (defel->
arg != NULL)
4429 requireSuper =
true;
4431 else if (strcmp(defel->
defname,
"subscript") == 0)
4433 if (defel->
arg != NULL)
4441 requireSuper =
true;
4448 else if (strcmp(defel->
defname,
"input") == 0 ||
4449 strcmp(defel->
defname,
"output") == 0 ||
4450 strcmp(defel->
defname,
"internallength") == 0 ||
4451 strcmp(defel->
defname,
"passedbyvalue") == 0 ||
4452 strcmp(defel->
defname,
"alignment") == 0 ||
4453 strcmp(defel->
defname,
"like") == 0 ||
4454 strcmp(defel->
defname,
"category") == 0 ||
4455 strcmp(defel->
defname,
"preferred") == 0 ||
4456 strcmp(defel->
defname,
"default") == 0 ||
4457 strcmp(defel->
defname,
"element") == 0 ||
4458 strcmp(defel->
defname,
"delimiter") == 0 ||
4459 strcmp(defel->
defname,
"collatable") == 0)
4461 (
errcode(ERRCODE_SYNTAX_ERROR),
4462 errmsg(
"type attribute \"%s\" cannot be changed",
4466 (
errcode(ERRCODE_SYNTAX_ERROR),
4467 errmsg(
"type attribute \"%s\" not recognized",
4479 (
errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4480 errmsg(
"must be superuser to alter a type")));
4498 if (typForm->typtype != TYPTYPE_BASE)
4500 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
4501 errmsg(
"%s is not a base type",
4507 if (IsTrueArrayType(typForm))
4509 (
errcode(ERRCODE_WRONG_OBJECT_TYPE),
4510 errmsg(
"%s is not a base type",
4555 bool nulls[Natts_pg_type];
4556 bool replaces[Natts_pg_type];
4567 memset(nulls, 0,
sizeof(nulls));
4568 memset(replaces, 0,
sizeof(replaces));
4572 replaces[Anum_pg_type_typstorage - 1] =
true;
4577 replaces[Anum_pg_type_typreceive - 1] =
true;
4582 replaces[Anum_pg_type_typsend - 1] =
true;
4587 replaces[Anum_pg_type_typmodin - 1] =
true;
4592 replaces[Anum_pg_type_typmodout - 1] =
true;
4597 replaces[Anum_pg_type_typanalyze - 1] =
true;
4602 replaces[Anum_pg_type_typsubscript - 1] =
true;
4607 values, nulls, replaces);
4629 if (!isImplicitArray &&
4641 elog(
ERROR,
"cache lookup failed for type %u", arrtypoid);
4643 memset(&arrparams, 0,
sizeof(arrparams));
4672 Anum_pg_type_typbasetype,
4687 if (domainForm->typtype != TYPTYPE_DOMAIN)
Acl * aclnewowner(const Acl *old_acl, Oid oldOwnerId, Oid newOwnerId)
void check_can_set_role(Oid member, Oid role)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
static Datum values[MAXATTR]
#define CStringGetTextDatum(s)
#define TextDatumGetCString(d)
#define PG_USED_FOR_ASSERTS_ONLY
#define Assert(condition)
#define OidIsValid(objectId)
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
TypeName * defGetTypeName(DefElem *def)
int defGetTypeLength(DefElem *def)
char * defGetString(DefElem *def)
bool defGetBoolean(DefElem *def)
List * defGetQualifiedName(DefElem *def)
void errorConflictingDefElem(DefElem *defel, ParseState *pstate)
void performDeletion(const ObjectAddress *object, DropBehavior behavior, int flags)
bool object_address_present(const ObjectAddress *object, const ObjectAddresses *addrs)
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
ObjectAddresses * new_object_addresses(void)
void free_object_addresses(ObjectAddresses *addrs)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
ExprState * ExecPrepareExpr(Expr *node, EState *estate)
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
void FreeExecutorState(EState *estate)
EState * CreateExecutorState(void)
#define GetPerTupleExprContext(estate)
#define ResetExprContext(econtext)
static Datum ExecEvalExprSwitchContext(ExprState *state, ExprContext *econtext, bool *isNull)
void systable_endscan(SysScanDesc sysscan)
HeapTuple systable_getnext(SysScanDesc sysscan)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Node * cookDefault(ParseState *pstate, Node *raw_default, Oid atttypid, int32 atttypmod, const char *attname, char attgenerated)
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)
HeapTuple heap_copytuple(HeapTuple tuple)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Oid GetDefaultOpClass(Oid type_id, Oid am_id)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
void CacheInvalidateHeapTuple(Relation relation, HeapTuple tuple, HeapTuple newtuple)
List * lappend(List *list, void *datum)
List * list_concat(List *list1, const List *list2)
#define AccessExclusiveLock
Oid get_element_type(Oid typid)
Oid get_opclass_input_type(Oid opclass)
Oid get_multirange_range(Oid multirangeOid)
bool get_typisdefined(Oid typid)
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
char get_rel_relkind(Oid relid)
Oid get_typcollation(Oid typid)
char func_volatile(Oid funcid)
char * get_func_name(Oid funcid)
Oid get_range_multirange(Oid rangeOid)
bool type_is_collatable(Oid typid)
int16 get_typlen(Oid typid)
char get_typtype(Oid typid)
char * get_namespace_name(Oid nspid)
Oid get_array_type(Oid typid)
Oid get_func_rettype(Oid funcid)
TypeName * makeTypeNameFromNameList(List *names)
void pfree(void *pointer)
Oid RangeVarGetAndCheckCreationNamespace(RangeVar *relation, LOCKMODE lockmode, Oid *existing_relation_id)
char * NameListToString(const List *names)
Oid QualifiedNameGetCreationNamespace(const List *names, char **objname_p)
Oid LookupCreationNamespace(const char *nspname)
void RangeVarAdjustRelationPersistence(RangeVar *newRelation, Oid nspid)
Oid get_collation_oid(List *collname, bool missing_ok)
void CheckSetNamespace(Oid oldNspOid, Oid nspOid)
#define IsA(nodeptr, _type_)
#define castNode(_type_, nodeptr)
#define InvokeObjectPostAlterHook(classId, objectId, subId)
const ObjectAddress InvalidObjectAddress
#define ObjectAddressSet(addr, class_id, object_id)
oidvector * buildoidvector(const Oid *oids, int n)
Oid get_opclass_oid(Oid amID, List *opclassname, bool missing_ok)
char * nodeToString(const void *obj)
bool IsBinaryCoercible(Oid srctype, Oid targettype)
Node * coerce_to_boolean(ParseState *pstate, Node *node, const char *constructName)
void assign_expr_collations(ParseState *pstate, Node *expr)
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
const char * func_signature_string(List *funcname, int nargs, List *argnames, const Oid *argtypes)
Oid LookupFuncName(List *funcname, int nargs, const Oid *argtypes, bool missing_ok)
static bool isCompositeType(Oid typid)
int parser_errposition(ParseState *pstate, int location)
ParseState * make_parsestate(ParseState *parentParseState)
char * TypeNameToString(const TypeName *typeName)
Type LookupTypeName(ParseState *pstate, const TypeName *typeName, int32 *typmod_p, bool missing_ok)
Type typenameType(ParseState *pstate, const TypeName *typeName, int32 *typmod_p)
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
@ CONSTR_ATTR_NOT_DEFERRABLE
@ CONSTR_ATTR_NOT_ENFORCED
FormData_pg_attribute * Form_pg_attribute
ObjectAddress CastCreate(Oid sourcetypeid, Oid targettypeid, Oid funcid, Oid incastid, Oid outcastid, char castcontext, char castmethod, DependencyType behavior)
Oid CreateConstraintEntry(const char *constraintName, Oid constraintNamespace, char constraintType, bool isDeferrable, bool isDeferred, bool isEnforced, bool isValidated, Oid parentConstrId, Oid relId, const int16 *constraintKey, int constraintNKeys, int constraintNTotalKeys, Oid domainId, Oid indexRelId, Oid foreignRelId, const int16 *foreignKey, const Oid *pfEqOp, const Oid *ppEqOp, const Oid *ffEqOp, int foreignNKeys, char foreignUpdateType, char foreignDeleteType, const int16 *fkDeleteSetCols, int numFkDeleteSetCols, char foreignMatchType, const Oid *exclOp, Node *conExpr, const char *conBin, bool conIsLocal, int16 conInhCount, bool conNoInherit, bool conPeriod, bool is_internal)
bool ConstraintNameIsUsed(ConstraintCategory conCat, Oid objId, const char *conname)
HeapTuple findDomainNotNullConstraint(Oid typid)
void AlterConstraintNamespaces(Oid ownerId, Oid oldNspId, Oid newNspId, bool isType, ObjectAddresses *objsMoved)
char * ChooseConstraintName(const char *name1, const char *name2, const char *label, Oid namespaceid, List *others)
FormData_pg_constraint * Form_pg_constraint
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
long changeDependencyFor(Oid classId, Oid objectId, Oid refClassId, Oid oldRefObjectId, Oid newRefObjectId)
FormData_pg_depend * Form_pg_depend
void RenameEnumLabel(Oid enumTypeOid, const char *oldVal, const char *newVal)
void EnumValuesDelete(Oid enumTypeOid)
void AddEnumLabel(Oid enumTypeOid, const char *newVal, const char *neighbor, bool newValIsAfter, bool skipIfExists)
void EnumValuesCreate(Oid enumTypeOid, List *vals)
static int list_length(const List *l)
ObjectAddress ProcedureCreate(const char *procedureName, Oid procNamespace, bool replace, bool returnsSet, Oid returnType, Oid proowner, Oid languageObjectId, Oid languageValidator, const char *prosrc, const char *probin, Node *prosqlbody, char prokind, bool security_definer, bool isLeakProof, bool isStrict, char volatility, char parallel, oidvector *parameterTypes, Datum allParameterTypes, Datum parameterModes, Datum parameterNames, List *parameterDefaults, Datum trftypes, Datum proconfig, Oid prosupport, float4 procost, float4 prorows)
void RangeCreate(Oid rangeTypeOid, Oid rangeSubType, Oid rangeCollation, Oid rangeSubOpclass, RegProcedure rangeCanonical, RegProcedure rangeSubDiff, Oid multirangeTypeOid)
void RangeDelete(Oid rangeTypeOid)
void changeDependencyOnOwner(Oid classId, Oid objectId, Oid newOwnerId)
void GenerateTypeDependencies(HeapTuple typeTuple, Relation typeCatalog, Node *defaultExpr, void *typacl, char relationKind, bool isImplicitArray, bool isDependentType, bool makeExtensionDep, bool rebuild)
void RenameTypeInternal(Oid typeOid, const char *newTypeName, Oid typeNamespace)
ObjectAddress TypeCreate(Oid newTypeOid, const char *typeName, Oid typeNamespace, Oid relationOid, char relationKind, Oid ownerId, int16 internalSize, char typeType, char typeCategory, bool typePreferred, char typDelim, Oid inputProcedure, Oid outputProcedure, Oid receiveProcedure, Oid sendProcedure, Oid typmodinProcedure, Oid typmodoutProcedure, Oid analyzeProcedure, Oid subscriptProcedure, Oid elementType, bool isImplicitArray, Oid arrayType, Oid baseType, const char *defaultTypeValue, char *defaultTypeBin, bool passedByValue, char alignment, char storage, int32 typeMod, int32 typNDims, bool typeNotNull, Oid typeCollation)
bool moveArrayTypeName(Oid typeOid, const char *typeName, Oid typeNamespace)
ObjectAddress TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
char * makeMultirangeTypeName(const char *rangeTypeName, Oid typeNamespace)
char * makeArrayTypeName(const char *typeName, Oid typeNamespace)
FormData_pg_type * Form_pg_type
int pg_strcasecmp(const char *s1, const char *s2)
static bool DatumGetBool(Datum X)
static Datum PointerGetDatum(const void *X)
static Datum ObjectIdGetDatum(Oid X)
static Datum NameGetDatum(const NameData *X)
static Datum CStringGetDatum(const char *X)
static Datum CharGetDatum(char X)
void * stringToNode(const char *str)
#define RelationGetRelid(relation)
#define RelationGetDescr(relation)
#define RelationGetNumberOfAttributes(relation)
#define RelationGetRelationName(relation)
int errtablecol(Relation rel, int attnum)
char * deparse_expression(Node *expr, List *dpcontext, bool forceprefix, bool showimplicit)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Snapshot GetLatestSnapshot(void)
void UnregisterSnapshot(Snapshot snapshot)
Snapshot RegisterSnapshot(Snapshot snapshot)
void relation_close(Relation relation, LOCKMODE lockmode)
Relation relation_open(Oid relationId, LOCKMODE lockmode)
void check_stack_depth(void)
#define BTEqualStrategyNumber
#define ERRCODE_DUPLICATE_OBJECT
PreParseColumnRefHook p_pre_columnref_hook
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
#define SearchSysCacheCopy1(cacheId, key1)