aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/functioncmds.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2002-09-21 18:39:26 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2002-09-21 18:39:26 +0000
commiteb3adab5685ce5a60bcf96628244f1e2a8e0ab3b (patch)
tree55ba25cb13ec6a414c7faf86a6d8da8357cfbfe7 /src/backend/commands/functioncmds.c
parentbc499687641a021e0dac3e146611b5a553cf0c5b (diff)
downloadpostgresql-eb3adab5685ce5a60bcf96628244f1e2a8e0ab3b.tar.gz
postgresql-eb3adab5685ce5a60bcf96628244f1e2a8e0ab3b.zip
Provide an upgrade strategy for dump files containing functions declared
with OPAQUE. CREATE LANGUAGE, CREATE TRIGGER, and CREATE TYPE will all accept references to functions declared with OPAQUE --- but they will issue a NOTICE, and will modify the function entries in pg_proc to have the preferred type-safe argument or result types instead of OPAQUE. Per recent pghackers discussions.
Diffstat (limited to 'src/backend/commands/functioncmds.c')
-rw-r--r--src/backend/commands/functioncmds.c81
1 files changed, 80 insertions, 1 deletions
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index f67538625ac..7857eb3bb3f 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.21 2002/09/18 21:35:20 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.22 2002/09/21 18:39:25 tgl Exp $
*
* DESCRIPTION
* These routines take the parse tree and pick out the
@@ -591,6 +591,85 @@ RemoveFunctionById(Oid funcOid)
}
+/*
+ * SetFunctionReturnType - change declared return type of a function
+ *
+ * This is presently only used for adjusting legacy functions that return
+ * OPAQUE to return whatever we find their correct definition should be.
+ * The caller should emit a suitable NOTICE explaining what we did.
+ */
+void
+SetFunctionReturnType(Oid funcOid, Oid newRetType)
+{
+ Relation pg_proc_rel;
+ HeapTuple tup;
+ Form_pg_proc procForm;
+
+ pg_proc_rel = heap_openr(ProcedureRelationName, RowExclusiveLock);
+
+ tup = SearchSysCacheCopy(PROCOID,
+ ObjectIdGetDatum(funcOid),
+ 0, 0, 0);
+ if (!HeapTupleIsValid(tup)) /* should not happen */
+ elog(ERROR, "SetFunctionReturnType: couldn't find tuple for function %u",
+ funcOid);
+ procForm = (Form_pg_proc) GETSTRUCT(tup);
+
+ if (procForm->prorettype != OPAQUEOID)
+ elog(ERROR, "SetFunctionReturnType: function %u doesn't return OPAQUE",
+ funcOid);
+
+ /* okay to overwrite copied tuple */
+ procForm->prorettype = newRetType;
+
+ /* update the catalog and its indexes */
+ simple_heap_update(pg_proc_rel, &tup->t_self, tup);
+
+ CatalogUpdateIndexes(pg_proc_rel, tup);
+
+ heap_close(pg_proc_rel, RowExclusiveLock);
+}
+
+
+/*
+ * SetFunctionArgType - change declared argument type of a function
+ *
+ * As above, but change an argument's type.
+ */
+void
+SetFunctionArgType(Oid funcOid, int argIndex, Oid newArgType)
+{
+ Relation pg_proc_rel;
+ HeapTuple tup;
+ Form_pg_proc procForm;
+
+ pg_proc_rel = heap_openr(ProcedureRelationName, RowExclusiveLock);
+
+ tup = SearchSysCacheCopy(PROCOID,
+ ObjectIdGetDatum(funcOid),
+ 0, 0, 0);
+ if (!HeapTupleIsValid(tup)) /* should not happen */
+ elog(ERROR, "SetFunctionArgType: couldn't find tuple for function %u",
+ funcOid);
+ procForm = (Form_pg_proc) GETSTRUCT(tup);
+
+ if (argIndex < 0 || argIndex >= procForm->pronargs ||
+ procForm->proargtypes[argIndex] != OPAQUEOID)
+ elog(ERROR, "SetFunctionArgType: function %u doesn't take OPAQUE",
+ funcOid);
+
+ /* okay to overwrite copied tuple */
+ procForm->proargtypes[argIndex] = newArgType;
+
+ /* update the catalog and its indexes */
+ simple_heap_update(pg_proc_rel, &tup->t_self, tup);
+
+ CatalogUpdateIndexes(pg_proc_rel, tup);
+
+ heap_close(pg_proc_rel, RowExclusiveLock);
+}
+
+
/*
* CREATE CAST