From: Chapman Flack Date: Mon, 21 Feb 2022 20:56:28 -0500 Subject: [PATCH 1/4] Warmup: add a get_call_trftypes function The existing get_func_trftypes function produces an Oid[], where both existing get_transform_{from,to}sql functions that depend on the result expect a List*. Rather than writing documentation awkwardly describing functions that won't play together, add a get_call_trftypes function that returns List*. (The name get_call_... to distinguish from get_func_... follows the naming used in funcapi.h for a function returning information about either a function or a procedure.) --- src/backend/utils/cache/lsyscache.c | 18 ++++++++++++++++++ src/include/funcapi.h | 5 +++++ src/include/utils/lsyscache.h | 1 + 3 files changed, 24 insertions(+) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index feef999..a49ccad 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2107,6 +2107,24 @@ get_transform_tosql(Oid typid, Oid langid, List *trftypes) return InvalidOid; } +/* + * get_call_trftypes + * + * A helper function that does not itself query the transform cache, but + * constructs the transform-type List expected by the functions above. + */ +List * +get_call_trftypes(HeapTuple procTup) +{ + Datum protrftypes; + bool isNull; + + protrftypes = SysCacheGetAttr(PROCOID, procTup, + Anum_pg_proc_protrftypes, + &isNull); + return isNull ? NIL : oid_array_to_list(protrftypes); +} + /* ---------- TYPE CACHE ---------- */ diff --git a/src/include/funcapi.h b/src/include/funcapi.h index ba927c2..7c61560 100644 --- a/src/include/funcapi.h +++ b/src/include/funcapi.h @@ -175,7 +175,12 @@ extern int get_func_arg_info(HeapTuple procTup, extern int get_func_input_arg_names(Datum proargnames, Datum proargmodes, char ***arg_names); +/* + * A deprecated earlier version of get_call_trftypes (in lsyscache.h). + * That version produces a List, which is the form downstream functions expect. + */ extern int get_func_trftypes(HeapTuple procTup, Oid **p_trftypes); + extern char *get_func_result_name(Oid functionId); extern TupleDesc build_function_result_tupdesc_d(char prokind, diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index b8dd27d..93b19e7 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -139,6 +139,7 @@ extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); +extern List *get_call_trftypes(HeapTuple procTup); extern Oid get_transform_fromsql(Oid typid, Oid langid, List *trftypes); extern Oid get_transform_tosql(Oid typid, Oid langid, List *trftypes); extern bool get_typisdefined(Oid typid); -- 2.7.3 --------------070002080407000808050907 Content-Type: text/x-patch; name="2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="2.patch"