diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-12-01 12:44:34 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-12-01 12:44:34 -0500 |
commit | 8a10fed4158fc135e68bd5ac3a7303072a844323 (patch) | |
tree | f8c143022f0b626caadb6c15e5079330b0e0e938 | |
parent | 0bb41ad4aa4b2bd5d8a1d2b262dc63a5dbdadc87 (diff) |
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
9bc933b2125a5358722490acbc50889887bf7680, 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.
-rw-r--r-- | src/backend/utils/cache/lsyscache.c | 2 | ||||
-rw-r--r-- | src/test/regress/expected/polymorphism.out | 21 | ||||
-rw-r--r-- | src/test/regress/sql/polymorphism.sql | 15 |
3 files changed, 37 insertions, 1 deletions
diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index e71ac3fb625..2250e854b9b 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -1821,7 +1821,7 @@ getTypeIOParam(HeapTuple typeTuple) * own type OID as parameter. (As of 8.2, domains must get their own OID * even if their base type is an array.) */ - if (typeStruct->typtype == TYPTYPE_BASE && OidIsValid(typeStruct->typelem)) + if (typeStruct->typtype != TYPTYPE_DOMAIN && OidIsValid(typeStruct->typelem)) return typeStruct->typelem; else return HeapTupleGetOid(typeTuple); diff --git a/src/test/regress/expected/polymorphism.out b/src/test/regress/expected/polymorphism.out index 77f693c2b14..5c25e4d31cd 100644 --- a/src/test/regress/expected/polymorphism.out +++ b/src/test/regress/expected/polymorphism.out @@ -577,6 +577,27 @@ select q2, sql_if(q2 > 0, q2, q2 + 1) from int8_tbl; -4567890123456789 | -4567890123456788 (5 rows) +-- another sort of polymorphic aggregate +CREATE AGGREGATE array_cat_accum (anyarray) +( + sfunc = array_cat, + stype = anyarray, + initcond = '{}' +); +SELECT array_cat_accum(i) +FROM (VALUES (ARRAY[1,2]), (ARRAY[3,4])) as t(i); + array_cat_accum +----------------- + {1,2,3,4} +(1 row) + +SELECT array_cat_accum(i) +FROM (VALUES (ARRAY[row(1,2),row(3,4)]), (ARRAY[row(5,6),row(7,8)])) as t(i); + array_cat_accum +----------------------------------- + {"(1,2)","(3,4)","(5,6)","(7,8)"} +(1 row) + -- another kind of polymorphic aggregate create function add_group(grp anyarray, ad anyelement, size integer) returns anyarray diff --git a/src/test/regress/sql/polymorphism.sql b/src/test/regress/sql/polymorphism.sql index c01871de007..e7c28e8bafd 100644 --- a/src/test/regress/sql/polymorphism.sql +++ b/src/test/regress/sql/polymorphism.sql @@ -391,6 +391,21 @@ select f1, sql_if(f1 > 0, bleat(f1), bleat(f1 + 1)) from int4_tbl; select q2, sql_if(q2 > 0, q2, q2 + 1) from int8_tbl; +-- another sort of polymorphic aggregate + +CREATE AGGREGATE array_cat_accum (anyarray) +( + sfunc = array_cat, + stype = anyarray, + initcond = '{}' +); + +SELECT array_cat_accum(i) +FROM (VALUES (ARRAY[1,2]), (ARRAY[3,4])) as t(i); + +SELECT array_cat_accum(i) +FROM (VALUES (ARRAY[row(1,2),row(3,4)]), (ARRAY[row(5,6),row(7,8)])) as t(i); + -- another kind of polymorphic aggregate create function add_group(grp anyarray, ad anyelement, size integer) |