]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix broken ruleutils support for function TRANSFORM clauses.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 25 Jan 2021 18:03:11 +0000 (13:03 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
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/adt/ruleutils.c
src/backend/utils/fmgr/funcapi.c

index 1ab5feea93d79fe426d0b5b19d79a4ef445c8da6..ecf1dd61bc17f9ec99ca5538b454de5d9e54900a 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 2c54ee6aaad264be8ceb28ff9bcd7e4e2d31c568..b6d98b7dd5371df8a2ac1fb04a7e7a2490b00e5b 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 1268ac1dd006b696d9b06774116c645724329540..b76ae9fddd5be39313618d9bf7b1a18e6a714a7a 100644 (file)
@@ -3103,13 +3103,14 @@ print_function_trftypes(StringInfo buf, HeapTuple proctup)
        {
                int                     i;
 
-               appendStringInfoString(buf, "\n TRANSFORM ");
+               appendStringInfoString(buf, " TRANSFORM ");
                for (i = 0; i < ntypes; i++)
                {
                        if (i != 0)
                                appendStringInfoString(buf, ", ");
                        appendStringInfo(buf, "FOR TYPE %s", format_type_be(trftypes[i]));
                }
+               appendStringInfoChar(buf, '\n');
        }
 }
 
index 206c3bd13e10aecf48888622c352fd481889b9e7..8632b1a29630761369807abdf78e5daf33c77992 100644 (file)
@@ -972,7 +972,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,
@@ -1001,7 +1003,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));