Fix broken ruleutils support for function TRANSFORM clauses.
authorTom Lane <[email protected]>
Mon, 25 Jan 2021 18:03:11 +0000 (13:03 -0500)
committerTom Lane <[email protected]>
Mon, 25 Jan 2021 18:03:11 +0000 (13:03 -0500)
I chanced to notice that this dumped core due to a faulty Assert.
To add insult to injury, the output has been misformatted since v11.
Obviously we need some regression testing here.

Discussion: https://postgr.es/m/d1cc628c-3953-4209-957b-29427acc38c8@www.fastmail.com

contrib/hstore_plpython/expected/hstore_plpython.out
contrib/hstore_plpython/sql/hstore_plpython.sql
src/backend/utils/fmgr/funcapi.c

index df49cd5f373a284738d5de90b95babf40472bbc7..4c4feaa15daf103fe60301abc4b59ed3f56cf5de 100644 (file)
@@ -47,19 +47,29 @@ SELECT test1arr(array['aa=>bb, cc=>NULL'::hstore, 'dd=>ee']);
 (1 row)
 
 -- test python -> hstore
-CREATE FUNCTION test2() RETURNS hstore
+CREATE FUNCTION test2(a int, b text) RETURNS hstore
 LANGUAGE plpythonu
 TRANSFORM FOR TYPE hstore
 AS $$
-val = {'a': 1, 'b': 'boo', 'c': None}
+val = {'a': a, 'b': b, 'c': None}
 return val
 $$;
-SELECT test2();
+SELECT test2(1, 'boo');
               test2              
 ---------------------------------
  "a"=>"1", "b"=>"boo", "c"=>NULL
 (1 row)
 
+--- test ruleutils
+\sf test2
+CREATE OR REPLACE FUNCTION public.test2(a integer, b text)
+ RETURNS hstore
+ TRANSFORM FOR TYPE hstore
+ LANGUAGE plpythonu
+AS $function$
+val = {'a': a, 'b': b, 'c': None}
+return val
+$function$
 -- test python -> hstore[]
 CREATE FUNCTION test2arr() RETURNS hstore[]
 LANGUAGE plpythonu
index 911bbd67fede733702ecd2bd405549c69762bbdd..7b7520d351c22460dbb5af54def7b77da10ca7cf 100644 (file)
@@ -40,15 +40,18 @@ SELECT test1arr(array['aa=>bb, cc=>NULL'::hstore, 'dd=>ee']);
 
 
 -- test python -> hstore
-CREATE FUNCTION test2() RETURNS hstore
+CREATE FUNCTION test2(a int, b text) RETURNS hstore
 LANGUAGE plpythonu
 TRANSFORM FOR TYPE hstore
 AS $$
-val = {'a': 1, 'b': 'boo', 'c': None}
+val = {'a': a, 'b': b, 'c': None}
 return val
 $$;
 
-SELECT test2();
+SELECT test2(1, 'boo');
+
+--- test ruleutils
+\sf test2
 
 
 -- test python -> hstore[]
index 4e432001e1bf068bd4d7a5f4c8a19d7d5235aff1..fb052c9919a55bd743c6f179f9f9a52cb93dbd1f 100644 (file)
@@ -934,7 +934,9 @@ get_func_arg_info(HeapTuple procTup,
 /*
  * get_func_trftypes
  *
- * Returns the number of transformed types used by function.
+ * Returns the number of transformed types used by the function.
+ * If there are any, a palloc'd array of the type OIDs is returned
+ * into *p_trftypes.
  */
 int
 get_func_trftypes(HeapTuple procTup,
@@ -963,7 +965,6 @@ get_func_trftypes(HeapTuple procTup,
            ARR_HASNULL(arr) ||
            ARR_ELEMTYPE(arr) != OIDOID)
            elog(ERROR, "protrftypes is not a 1-D Oid array");
-       Assert(nelems >= ((Form_pg_proc) GETSTRUCT(procTup))->pronargs);
        *p_trftypes = (Oid *) palloc(nelems * sizeof(Oid));
        memcpy(*p_trftypes, ARR_DATA_PTR(arr),
               nelems * sizeof(Oid));