diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-01-11 18:39:41 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-01-11 18:39:41 +0000 |
| commit | 89c0a87fda06aade58831976c9dbc97134032d18 (patch) | |
| tree | df2e897b30dc3b65597a34820ce87af3e101b227 /src/test | |
| parent | df62977d0080e9e437c74f456d96318e8e0a56ee (diff) | |
| download | postgresql-89c0a87fda06aade58831976c9dbc97134032d18.tar.gz | |
The original implementation of polymorphic aggregates didn't really get the
checking of argument compatibility right; although the problem is only exposed
with multiple-input aggregates in which some arguments are polymorphic and
some are not. Per bug #3852 from Sokolov Yura.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/polymorphism.out | 36 | ||||
| -rw-r--r-- | src/test/regress/sql/polymorphism.sql | 36 |
2 files changed, 72 insertions, 0 deletions
diff --git a/src/test/regress/expected/polymorphism.out b/src/test/regress/expected/polymorphism.out index de393a0528..a208203c6d 100644 --- a/src/test/regress/expected/polymorphism.out +++ b/src/test/regress/expected/polymorphism.out @@ -577,3 +577,39 @@ select q2, sql_if(q2 > 0, q2, q2 + 1) from int8_tbl; -4567890123456789 | -4567890123456788 (5 rows) +-- another kind of polymorphic aggregate +create function add_group(grp anyarray, ad anyelement, size integer) + returns anyarray + as $$ +begin + if grp is null then + return array[ad]; + end if; + if array_upper(grp, 1) < size then + return grp || ad; + end if; + return grp; +end; +$$ + language plpgsql immutable; +create aggregate build_group(anyelement, integer) ( + SFUNC = add_group, + STYPE = anyarray +); +select build_group(q1,3) from int8_tbl; + build_group +---------------------------- + {123,123,4567890123456789} +(1 row) + +-- this should fail because stype isn't compatible with arg +create aggregate build_group(int8, integer) ( + SFUNC = add_group, + STYPE = int2[] +); +ERROR: function add_group(smallint[], bigint, integer) does not exist +-- but we can make a non-poly agg from a poly sfunc if types are OK +create aggregate build_group(int8, integer) ( + SFUNC = add_group, + STYPE = int8[] +); diff --git a/src/test/regress/sql/polymorphism.sql b/src/test/regress/sql/polymorphism.sql index c2bf14b48f..2df963952f 100644 --- a/src/test/regress/sql/polymorphism.sql +++ b/src/test/regress/sql/polymorphism.sql @@ -390,3 +390,39 @@ select case when $1 then $2 else $3 end $$ language sql; 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 kind of polymorphic aggregate + +create function add_group(grp anyarray, ad anyelement, size integer) + returns anyarray + as $$ +begin + if grp is null then + return array[ad]; + end if; + if array_upper(grp, 1) < size then + return grp || ad; + end if; + return grp; +end; +$$ + language plpgsql immutable; + +create aggregate build_group(anyelement, integer) ( + SFUNC = add_group, + STYPE = anyarray +); + +select build_group(q1,3) from int8_tbl; + +-- this should fail because stype isn't compatible with arg +create aggregate build_group(int8, integer) ( + SFUNC = add_group, + STYPE = int2[] +); + +-- but we can make a non-poly agg from a poly sfunc if types are OK +create aggregate build_group(int8, integer) ( + SFUNC = add_group, + STYPE = int8[] +); |
