Skip to content

Commit a7cdd3f

Browse files
committed
Fix broken ruleutils support for function TRANSFORM clauses.
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
1 parent 34eeebb commit a7cdd3f

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

contrib/hstore_plpython/expected/hstore_plpython.out

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,29 @@ SELECT test1arr(array['aa=>bb, cc=>NULL'::hstore, 'dd=>ee']);
4747
(1 row)
4848

4949
-- test python -> hstore
50-
CREATE FUNCTION test2() RETURNS hstore
50+
CREATE FUNCTION test2(a int, b text) RETURNS hstore
5151
LANGUAGE plpythonu
5252
TRANSFORM FOR TYPE hstore
5353
AS $$
54-
val = {'a': 1, 'b': 'boo', 'c': None}
54+
val = {'a': a, 'b': b, 'c': None}
5555
return val
5656
$$;
57-
SELECT test2();
57+
SELECT test2(1, 'boo');
5858
test2
5959
---------------------------------
6060
"a"=>"1", "b"=>"boo", "c"=>NULL
6161
(1 row)
6262

63+
--- test ruleutils
64+
\sf test2
65+
CREATE OR REPLACE FUNCTION public.test2(a integer, b text)
66+
RETURNS hstore
67+
TRANSFORM FOR TYPE hstore
68+
LANGUAGE plpythonu
69+
AS $function$
70+
val = {'a': a, 'b': b, 'c': None}
71+
return val
72+
$function$
6373
-- test python -> hstore[]
6474
CREATE FUNCTION test2arr() RETURNS hstore[]
6575
LANGUAGE plpythonu

contrib/hstore_plpython/sql/hstore_plpython.sql

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,18 @@ SELECT test1arr(array['aa=>bb, cc=>NULL'::hstore, 'dd=>ee']);
4040

4141

4242
-- test python -> hstore
43-
CREATE FUNCTION test2() RETURNS hstore
43+
CREATE FUNCTION test2(a int, b text) RETURNS hstore
4444
LANGUAGE plpythonu
4545
TRANSFORM FOR TYPE hstore
4646
AS $$
47-
val = {'a': 1, 'b': 'boo', 'c': None}
47+
val = {'a': a, 'b': b, 'c': None}
4848
return val
4949
$$;
5050

51-
SELECT test2();
51+
SELECT test2(1, 'boo');
52+
53+
--- test ruleutils
54+
\sf test2
5255

5356

5457
-- test python -> hstore[]

src/backend/utils/adt/ruleutils.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3043,13 +3043,14 @@ print_function_trftypes(StringInfo buf, HeapTuple proctup)
30433043
{
30443044
int i;
30453045

3046-
appendStringInfoString(buf, "\n TRANSFORM ");
3046+
appendStringInfoString(buf, " TRANSFORM ");
30473047
for (i = 0; i < ntypes; i++)
30483048
{
30493049
if (i != 0)
30503050
appendStringInfoString(buf, ", ");
30513051
appendStringInfo(buf, "FOR TYPE %s", format_type_be(trftypes[i]));
30523052
}
3053+
appendStringInfoChar(buf, '\n');
30533054
}
30543055
}
30553056

src/backend/utils/fmgr/funcapi.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,9 @@ get_func_arg_info(HeapTuple procTup,
987987
/*
988988
* get_func_trftypes
989989
*
990-
* Returns the number of transformed types used by function.
990+
* Returns the number of transformed types used by the function.
991+
* If there are any, a palloc'd array of the type OIDs is returned
992+
* into *p_trftypes.
991993
*/
992994
int
993995
get_func_trftypes(HeapTuple procTup,
@@ -1016,7 +1018,6 @@ get_func_trftypes(HeapTuple procTup,
10161018
ARR_HASNULL(arr) ||
10171019
ARR_ELEMTYPE(arr) != OIDOID)
10181020
elog(ERROR, "protrftypes is not a 1-D Oid array");
1019-
Assert(nelems >= ((Form_pg_proc) GETSTRUCT(procTup))->pronargs);
10201021
*p_trftypes = (Oid *) palloc(nelems * sizeof(Oid));
10211022
memcpy(*p_trftypes, ARR_DATA_PTR(arr),
10221023
nelems * sizeof(Oid));

0 commit comments

Comments
 (0)