Skip to content

Commit 4641b2a

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 06cdfe2 commit 4641b2a

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
@@ -3103,13 +3103,14 @@ print_function_trftypes(StringInfo buf, HeapTuple proctup)
31033103
{
31043104
int i;
31053105

3106-
appendStringInfoString(buf, "\n TRANSFORM ");
3106+
appendStringInfoString(buf, " TRANSFORM ");
31073107
for (i = 0; i < ntypes; i++)
31083108
{
31093109
if (i != 0)
31103110
appendStringInfoString(buf, ", ");
31113111
appendStringInfo(buf, "FOR TYPE %s", format_type_be(trftypes[i]));
31123112
}
3113+
appendStringInfoChar(buf, '\n');
31133114
}
31143115
}
31153116

src/backend/utils/fmgr/funcapi.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,9 @@ get_func_arg_info(HeapTuple procTup,
972972
/*
973973
* get_func_trftypes
974974
*
975-
* Returns the number of transformed types used by function.
975+
* Returns the number of transformed types used by the function.
976+
* If there are any, a palloc'd array of the type OIDs is returned
977+
* into *p_trftypes.
976978
*/
977979
int
978980
get_func_trftypes(HeapTuple procTup,
@@ -1001,7 +1003,6 @@ get_func_trftypes(HeapTuple procTup,
10011003
ARR_HASNULL(arr) ||
10021004
ARR_ELEMTYPE(arr) != OIDOID)
10031005
elog(ERROR, "protrftypes is not a 1-D Oid array");
1004-
Assert(nelems >= ((Form_pg_proc) GETSTRUCT(procTup))->pronargs);
10051006
*p_trftypes = (Oid *) palloc(nelems * sizeof(Oid));
10061007
memcpy(*p_trftypes, ARR_DATA_PTR(arr),
10071008
nelems * sizeof(Oid));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy