aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/typecmds.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-12-11 18:07:02 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2020-12-11 18:58:21 -0500
commit8c15a297452e970d68529ee2ce6bd94d84598409 (patch)
treebba36417e47b3db35288e5f96db0226d947e04e3 /src/backend/commands/typecmds.c
parent653aa603f501aa6e4865105a928cd13082ee7152 (diff)
downloadpostgresql-8c15a297452e970d68529ee2ce6bd94d84598409.tar.gz
postgresql-8c15a297452e970d68529ee2ce6bd94d84598409.zip
Allow ALTER TYPE to update an existing type's typsubscript value.
This is essential if we'd like to allow existing extension data types to support subscripting in future, since dropping and recreating the type isn't a practical thing for an extension upgrade script, and direct manipulation of pg_type isn't a great answer either. There was some discussion about also allowing alteration of typelem, but it's less clear whether that's a good idea or not, so for now I forebore. Discussion: https://postgr.es/m/3724341.1607551174@sss.pgh.pa.us
Diffstat (limited to 'src/backend/commands/typecmds.c')
-rw-r--r--src/backend/commands/typecmds.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c
index 29fe52d2cef..7c0b2c3bf02 100644
--- a/src/backend/commands/typecmds.c
+++ b/src/backend/commands/typecmds.c
@@ -94,6 +94,7 @@ typedef struct
bool updateTypmodin;
bool updateTypmodout;
bool updateAnalyze;
+ bool updateSubscript;
/* New values for relevant attributes */
char storage;
Oid receiveOid;
@@ -101,6 +102,7 @@ typedef struct
Oid typmodinOid;
Oid typmodoutOid;
Oid analyzeOid;
+ Oid subscriptOid;
} AlterTypeRecurseParams;
/* Potentially set by pg_upgrade_support functions */
@@ -3885,6 +3887,18 @@ AlterType(AlterTypeStmt *stmt)
/* Replacing an analyze function requires superuser. */
requireSuper = true;
}
+ else if (strcmp(defel->defname, "subscript") == 0)
+ {
+ if (defel->arg != NULL)
+ atparams.subscriptOid =
+ findTypeSubscriptingFunction(defGetQualifiedName(defel),
+ typeOid);
+ else
+ atparams.subscriptOid = InvalidOid; /* NONE, remove function */
+ atparams.updateSubscript = true;
+ /* Replacing a subscript function requires superuser. */
+ requireSuper = true;
+ }
/*
* The rest of the options that CREATE accepts cannot be changed.
@@ -4042,6 +4056,11 @@ AlterTypeRecurse(Oid typeOid, bool isImplicitArray,
replaces[Anum_pg_type_typanalyze - 1] = true;
values[Anum_pg_type_typanalyze - 1] = ObjectIdGetDatum(atparams->analyzeOid);
}
+ if (atparams->updateSubscript)
+ {
+ replaces[Anum_pg_type_typsubscript - 1] = true;
+ values[Anum_pg_type_typsubscript - 1] = ObjectIdGetDatum(atparams->subscriptOid);
+ }
newtup = heap_modify_tuple(tup, RelationGetDescr(catalog),
values, nulls, replaces);
@@ -4098,6 +4117,7 @@ AlterTypeRecurse(Oid typeOid, bool isImplicitArray,
atparams->updateReceive = false; /* domains use F_DOMAIN_RECV */
atparams->updateTypmodin = false; /* domains don't have typmods */
atparams->updateTypmodout = false;
+ atparams->updateSubscript = false; /* domains don't have subscriptors */
/* Skip the scan if nothing remains to be done */
if (!(atparams->updateStorage ||