Commit 65d9aedb authored by Tom Lane's avatar Tom Lane

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
9bc933b2, 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.
parent 1be6f937
...@@ -1890,10 +1890,9 @@ getTypeIOParam(HeapTuple typeTuple) ...@@ -1890,10 +1890,9 @@ getTypeIOParam(HeapTuple typeTuple)
/* /*
* Array types get their typelem as parameter; everybody else gets their * Array types get their typelem as parameter; everybody else gets their
* own type OID as parameter. (As of 8.2, domains must get their own OID * own type OID as parameter.
* even if their base type is an array.)
*/ */
if (typeStruct->typtype == TYPTYPE_BASE && OidIsValid(typeStruct->typelem)) if (OidIsValid(typeStruct->typelem))
return typeStruct->typelem; return typeStruct->typelem;
else else
return HeapTupleGetOid(typeTuple); return HeapTupleGetOid(typeTuple);
......
...@@ -578,6 +578,27 @@ select q2, sql_if(q2 > 0, q2, q2 + 1) from int8_tbl; ...@@ -578,6 +578,27 @@ select q2, sql_if(q2 > 0, q2, q2 + 1) from int8_tbl;
-4567890123456789 | -4567890123456788 -4567890123456789 | -4567890123456788
(5 rows) (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 -- another kind of polymorphic aggregate
create function add_group(grp anyarray, ad anyelement, size integer) create function add_group(grp anyarray, ad anyelement, size integer)
returns anyarray returns anyarray
......
...@@ -392,6 +392,21 @@ select f1, sql_if(f1 > 0, bleat(f1), bleat(f1 + 1)) from int4_tbl; ...@@ -392,6 +392,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; 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 -- another kind of polymorphic aggregate
create function add_group(grp anyarray, ad anyelement, size integer) create function add_group(grp anyarray, ad anyelement, size integer)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment