Skip to content

Commit 57a7d6f

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 317de9c commit 57a7d6f

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

contrib/hstore_plpython/expected/hstore_plpython.out

+13-3
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,29 @@ SELECT test1arr(array['aa=>bb, cc=>NULL'::hstore, 'dd=>ee']);
5151
(1 row)
5252

5353
-- test python -> hstore
54-
CREATE FUNCTION test2() RETURNS hstore
54+
CREATE FUNCTION test2(a int, b text) RETURNS hstore
5555
LANGUAGE plpythonu
5656
TRANSFORM FOR TYPE hstore
5757
AS $$
58-
val = {'a': 1, 'b': 'boo', 'c': None}
58+
val = {'a': a, 'b': b, 'c': None}
5959
return val
6060
$$;
61-
SELECT test2();
61+
SELECT test2(1, 'boo');
6262
test2
6363
---------------------------------
6464
"a"=>"1", "b"=>"boo", "c"=>NULL
6565
(1 row)
6666

67+
--- test ruleutils
68+
\sf test2
69+
CREATE OR REPLACE FUNCTION public.test2(a integer, b text)
70+
RETURNS hstore
71+
TRANSFORM FOR TYPE hstore
72+
LANGUAGE plpythonu
73+
AS $function$
74+
val = {'a': a, 'b': b, 'c': None}
75+
return val
76+
$function$
6777
-- test python -> hstore[]
6878
CREATE FUNCTION test2arr() RETURNS hstore[]
6979
LANGUAGE plpythonu

contrib/hstore_plpython/sql/hstore_plpython.sql

+6-3
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,18 @@ SELECT test1arr(array['aa=>bb, cc=>NULL'::hstore, 'dd=>ee']);
4444

4545

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

55-
SELECT test2();
55+
SELECT test2(1, 'boo');
56+
57+
--- test ruleutils
58+
\sf test2
5659

5760

5861
-- test python -> hstore[]

src/backend/utils/fmgr/funcapi.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,9 @@ get_func_arg_info(HeapTuple procTup,
933933
/*
934934
* get_func_trftypes
935935
*
936-
* Returns the number of transformed types used by function.
936+
* Returns the number of transformed types used by the function.
937+
* If there are any, a palloc'd array of the type OIDs is returned
938+
* into *p_trftypes.
937939
*/
938940
int
939941
get_func_trftypes(HeapTuple procTup,
@@ -962,7 +964,6 @@ get_func_trftypes(HeapTuple procTup,
962964
ARR_HASNULL(arr) ||
963965
ARR_ELEMTYPE(arr) != OIDOID)
964966
elog(ERROR, "protrftypes is not a 1-D Oid array");
965-
Assert(nelems >= ((Form_pg_proc) GETSTRUCT(procTup))->pronargs);
966967
*p_trftypes = (Oid *) palloc(nelems * sizeof(Oid));
967968
memcpy(*p_trftypes, ARR_DATA_PTR(arr),
968969
nelems * sizeof(Oid));

0 commit comments

Comments
 (0)