Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit07d46fc

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 parentd18e756 commit07d46fc

File tree

8 files changed

+66
-13
lines changed

8 files changed

+66
-13
lines changed

‎contrib/bool_plperl/expected/bool_plperl.out

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ SELECT perl2undef() IS NULL AS p;
5252
--- test transforming to perl
5353
CREATE FUNCTION bool2perl(bool, bool, bool) RETURNS void
5454
LANGUAGE plperl
55-
TRANSFORM FOR TYPE bool
55+
TRANSFORM FOR TYPE bool, for type boolean -- duplicate to test ruleutils
5656
AS $$
5757
my ($x, $y, $z) = @_;
5858

@@ -68,6 +68,21 @@ SELECT bool2perl (true, false, NULL);
6868

6969
(1 row)
7070

71+
--- test ruleutils
72+
\sf bool2perl
73+
CREATE OR REPLACE FUNCTION public.bool2perl(boolean, boolean, boolean)
74+
RETURNS void
75+
TRANSFORM FOR TYPE boolean, FOR TYPE boolean
76+
LANGUAGE plperl
77+
AS $function$
78+
my ($x, $y, $z) = @_;
79+
80+
die("NULL mistransformed") if (defined($z));
81+
die("TRUE mistransformed to UNDEF") if (!defined($x));
82+
die("FALSE mistransformed to UNDEF") if (!defined($y));
83+
die("TRUE mistransformed") if (!$x);
84+
die("FALSE mistransformed") if ($y);
85+
$function$
7186
--- test selecting bool through SPI
7287
CREATE FUNCTION spi_test() RETURNS void
7388
LANGUAGE plperl

‎contrib/bool_plperl/expected/bool_plperlu.out

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ SELECT perl2undef() IS NULL AS p;
5252
--- test transforming to perl
5353
CREATE FUNCTION bool2perl(bool, bool, bool) RETURNS void
5454
LANGUAGE plperlu
55-
TRANSFORM FOR TYPE bool
55+
TRANSFORM FOR TYPE bool, for type boolean -- duplicate to test ruleutils
5656
AS $$
5757
my ($x, $y, $z) = @_;
5858

@@ -68,6 +68,21 @@ SELECT bool2perl (true, false, NULL);
6868

6969
(1 row)
7070

71+
--- test ruleutils
72+
\sf bool2perl
73+
CREATE OR REPLACE FUNCTION public.bool2perl(boolean, boolean, boolean)
74+
RETURNS void
75+
TRANSFORM FOR TYPE boolean, FOR TYPE boolean
76+
LANGUAGE plperlu
77+
AS $function$
78+
my ($x, $y, $z) = @_;
79+
80+
die("NULL mistransformed") if (defined($z));
81+
die("TRUE mistransformed to UNDEF") if (!defined($x));
82+
die("FALSE mistransformed to UNDEF") if (!defined($y));
83+
die("TRUE mistransformed") if (!$x);
84+
die("FALSE mistransformed") if ($y);
85+
$function$
7186
--- test selecting bool through SPI
7287
CREATE FUNCTION spi_test() RETURNS void
7388
LANGUAGE plperlu

‎contrib/bool_plperl/sql/bool_plperl.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ SELECT perl2undef() IS NULL AS p;
3333

3434
CREATEFUNCTIONbool2perl(bool, bool, bool) RETURNS void
3535
LANGUAGE plperl
36-
TRANSFORM FOR TYPE bool
36+
TRANSFORM FOR TYPE bool, for typeboolean-- duplicate to test ruleutils
3737
AS $$
3838
my ($x, $y, $z)= @_;
3939

@@ -46,6 +46,10 @@ $$;
4646

4747
SELECT bool2perl (true, false,NULL);
4848

49+
--- test ruleutils
50+
51+
\sf bool2perl
52+
4953
--- test selecting bool through SPI
5054

5155
CREATEFUNCTIONspi_test() RETURNS void

‎contrib/bool_plperl/sql/bool_plperlu.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ SELECT perl2undef() IS NULL AS p;
3333

3434
CREATEFUNCTIONbool2perl(bool, bool, bool) RETURNS void
3535
LANGUAGE plperlu
36-
TRANSFORM FOR TYPE bool
36+
TRANSFORM FOR TYPE bool, for typeboolean-- duplicate to test ruleutils
3737
AS $$
3838
my ($x, $y, $z)= @_;
3939

@@ -46,6 +46,10 @@ $$;
4646

4747
SELECT bool2perl (true, false,NULL);
4848

49+
--- test ruleutils
50+
51+
\sf bool2perl
52+
4953
--- test selecting bool through SPI
5054

5155
CREATEFUNCTIONspi_test() RETURNS void

‎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-
CREATEFUNCTIONtest2() RETURNS hstore
43+
CREATEFUNCTIONtest2(aint, btext) 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
@@ -3126,13 +3126,14 @@ print_function_trftypes(StringInfo buf, HeapTuple proctup)
31263126
{
31273127
inti;
31283128

3129-
appendStringInfoString(buf,"\n TRANSFORM ");
3129+
appendStringInfoString(buf," TRANSFORM ");
31303130
for (i=0;i<ntypes;i++)
31313131
{
31323132
if (i!=0)
31333133
appendStringInfoString(buf,", ");
31343134
appendStringInfo(buf,"FOR TYPE %s",format_type_be(trftypes[i]));
31353135
}
3136+
appendStringInfoChar(buf,'\n');
31363137
}
31373138
}
31383139

‎src/backend/utils/fmgr/funcapi.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,9 @@ get_func_arg_info(HeapTuple procTup,
13571357
/*
13581358
* get_func_trftypes
13591359
*
1360-
* Returns the number of transformed types used by function.
1360+
* Returns the number of transformed types used by the function.
1361+
* If there are any, a palloc'd array of the type OIDs is returned
1362+
* into *p_trftypes.
13611363
*/
13621364
int
13631365
get_func_trftypes(HeapTupleprocTup,
@@ -1386,7 +1388,6 @@ get_func_trftypes(HeapTuple procTup,
13861388
ARR_HASNULL(arr)||
13871389
ARR_ELEMTYPE(arr)!=OIDOID)
13881390
elog(ERROR,"protrftypes is not a 1-D Oid array or it contains nulls");
1389-
Assert(nelems >= ((Form_pg_proc)GETSTRUCT(procTup))->pronargs);
13901391
*p_trftypes= (Oid*)palloc(nelems*sizeof(Oid));
13911392
memcpy(*p_trftypes,ARR_DATA_PTR(arr),
13921393
nelems*sizeof(Oid));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp