Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ac3dcca

Browse files
committed
Fix getTypeIOParam to support type record[].
Since record[] uses array_in, it needs to have its element type passed as typioparam. In HEAD and 9.1, this fix essentially reverts commit 9bc933b, which was a hack that is no longer needed since domains don't set their typelem anymore. Before that, adjust the logic so that only domains are excluded from being treated like arrays, rather than assuming that only base types should be included. Add a regression test to demonstrate the need for this. Per report from Maxim Boguk. Back-patch to 8.4, where type record[] was added.
1 parent 0f90fb9 commit ac3dcca

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/backend/utils/cache/lsyscache.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,10 +1888,9 @@ getTypeIOParam(HeapTuple typeTuple)
18881888

18891889
/*
18901890
* Array types get their typelem as parameter; everybody else gets their
1891-
* own type OID as parameter. (As of 8.2, domains must get their own OID
1892-
* even if their base type is an array.)
1891+
* own type OID as parameter.
18931892
*/
1894-
if (typeStruct->typtype == TYPTYPE_BASE && OidIsValid(typeStruct->typelem))
1893+
if (OidIsValid(typeStruct->typelem))
18951894
return typeStruct->typelem;
18961895
else
18971896
return HeapTupleGetOid(typeTuple);

src/test/regress/expected/polymorphism.out

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,27 @@ select q2, sql_if(q2 > 0, q2, q2 + 1) from int8_tbl;
578578
-4567890123456789 | -4567890123456788
579579
(5 rows)
580580

581+
-- another sort of polymorphic aggregate
582+
CREATE AGGREGATE array_cat_accum (anyarray)
583+
(
584+
sfunc = array_cat,
585+
stype = anyarray,
586+
initcond = '{}'
587+
);
588+
SELECT array_cat_accum(i)
589+
FROM (VALUES (ARRAY[1,2]), (ARRAY[3,4])) as t(i);
590+
array_cat_accum
591+
-----------------
592+
{1,2,3,4}
593+
(1 row)
594+
595+
SELECT array_cat_accum(i)
596+
FROM (VALUES (ARRAY[row(1,2),row(3,4)]), (ARRAY[row(5,6),row(7,8)])) as t(i);
597+
array_cat_accum
598+
-----------------------------------
599+
{"(1,2)","(3,4)","(5,6)","(7,8)"}
600+
(1 row)
601+
581602
-- another kind of polymorphic aggregate
582603
create function add_group(grp anyarray, ad anyelement, size integer)
583604
returns anyarray

src/test/regress/sql/polymorphism.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,21 @@ select f1, sql_if(f1 > 0, bleat(f1), bleat(f1 + 1)) from int4_tbl;
392392

393393
select q2, sql_if(q2 > 0, q2, q2 + 1) from int8_tbl;
394394

395+
-- another sort of polymorphic aggregate
396+
397+
CREATE AGGREGATE array_cat_accum (anyarray)
398+
(
399+
sfunc = array_cat,
400+
stype = anyarray,
401+
initcond = '{}'
402+
);
403+
404+
SELECT array_cat_accum(i)
405+
FROM (VALUES (ARRAY[1,2]), (ARRAY[3,4])) as t(i);
406+
407+
SELECT array_cat_accum(i)
408+
FROM (VALUES (ARRAY[row(1,2),row(3,4)]), (ARRAY[row(5,6),row(7,8)])) as t(i);
409+
395410
-- another kind of polymorphic aggregate
396411

397412
create function add_group(grp anyarray, ad anyelement, size integer)

0 commit comments

Comments
 (0)