Commit b7ea0e8c authored by Tom Lane's avatar Tom Lane

Fix bugs in polymorphic-argument resolution for multiranges.

We failed to deal with an UNKNOWN-type input for
anycompatiblemultirange; that should throw an error indicating
that we don't know how to resolve the multirange type.

We also failed to infer the type of an anycompatiblerange output
from an anycompatiblemultirange input or vice versa.

Per bug #17066 from Alexander Lakhin.  Back-patch to v14
where multiranges were added.

Discussion: https://postgr.es/m/17066-16a37f6223a8470b@postgresql.org
parent fd90f6ba
This diff is collapsed.
...@@ -179,6 +179,72 @@ LINE 2: from polyf(11, array[1, 2.2], 42, 34.5); ...@@ -179,6 +179,72 @@ LINE 2: from polyf(11, array[1, 2.2], 42, 34.5);
HINT: No function matches the given name and argument types. You might need to add explicit type casts. HINT: No function matches the given name and argument types. You might need to add explicit type casts.
drop function polyf(a anyelement, b anyarray, drop function polyf(a anyelement, b anyarray,
c anycompatible, d anycompatible); c anycompatible, d anycompatible);
create function polyf(anyrange) returns anymultirange
as 'select multirange($1);' language sql;
select polyf(int4range(1,10));
polyf
----------
{[1,10)}
(1 row)
select polyf(null);
ERROR: could not determine polymorphic type because input has type unknown
drop function polyf(anyrange);
create function polyf(anymultirange) returns anyelement
as 'select lower($1);' language sql;
select polyf(int4multirange(int4range(1,10), int4range(20,30)));
polyf
-------
1
(1 row)
select polyf(null);
ERROR: could not determine polymorphic type because input has type unknown
drop function polyf(anymultirange);
create function polyf(anycompatiblerange) returns anycompatiblemultirange
as 'select multirange($1);' language sql;
select polyf(int4range(1,10));
polyf
----------
{[1,10)}
(1 row)
select polyf(null);
ERROR: could not determine polymorphic type anycompatiblerange because input has type unknown
drop function polyf(anycompatiblerange);
create function polyf(anymultirange) returns anyrange
as 'select range_merge($1);' language sql;
select polyf(int4multirange(int4range(1,10), int4range(20,30)));
polyf
--------
[1,30)
(1 row)
select polyf(null);
ERROR: could not determine polymorphic type because input has type unknown
drop function polyf(anymultirange);
create function polyf(anycompatiblemultirange) returns anycompatiblerange
as 'select range_merge($1);' language sql;
select polyf(int4multirange(int4range(1,10), int4range(20,30)));
polyf
--------
[1,30)
(1 row)
select polyf(null);
ERROR: could not determine polymorphic type anycompatiblerange because input has type unknown
drop function polyf(anycompatiblemultirange);
create function polyf(anycompatiblemultirange) returns anycompatible
as 'select lower($1);' language sql;
select polyf(int4multirange(int4range(1,10), int4range(20,30)));
polyf
-------
1
(1 row)
select polyf(null);
ERROR: could not determine polymorphic type anycompatiblemultirange because input has type unknown
drop function polyf(anycompatiblemultirange);
-- --
-- Polymorphic aggregate tests -- Polymorphic aggregate tests
-- --
...@@ -1914,7 +1980,7 @@ LINE 1: select x, pg_typeof(x) from anyctest(11.2, multirange(int4ra... ...@@ -1914,7 +1980,7 @@ LINE 1: select x, pg_typeof(x) from anyctest(11.2, multirange(int4ra...
^ ^
HINT: No function matches the given name and argument types. You might need to add explicit type casts. HINT: No function matches the given name and argument types. You might need to add explicit type casts.
select x, pg_typeof(x) from anyctest(11.2, '{[4,7)}') x; -- fail select x, pg_typeof(x) from anyctest(11.2, '{[4,7)}') x; -- fail
ERROR: could not identify anycompatiblemultirange type ERROR: could not determine polymorphic type anycompatiblemultirange because input has type unknown
drop function anyctest(anycompatible, anycompatiblemultirange); drop function anyctest(anycompatible, anycompatiblemultirange);
create function anyctest(anycompatiblemultirange, anycompatiblemultirange) create function anyctest(anycompatiblemultirange, anycompatiblemultirange)
returns anycompatible as $$ returns anycompatible as $$
......
...@@ -1609,7 +1609,7 @@ DROP FUNCTION dup(f1 anycompatiblerange); ...@@ -1609,7 +1609,7 @@ DROP FUNCTION dup(f1 anycompatiblerange);
CREATE FUNCTION bad (f1 anyarray, out f2 anycompatible, out f3 anycompatiblearray) CREATE FUNCTION bad (f1 anyarray, out f2 anycompatible, out f3 anycompatiblearray)
AS 'select $1, array[$1,$1]' LANGUAGE sql; AS 'select $1, array[$1,$1]' LANGUAGE sql;
ERROR: cannot determine result data type ERROR: cannot determine result data type
DETAIL: A result of type anycompatible requires at least one input of type anycompatible, anycompatiblearray, anycompatiblenonarray, or anycompatiblerange. DETAIL: A result of type anycompatible requires at least one input of type anycompatible, anycompatiblearray, anycompatiblenonarray, anycompatiblerange, or anycompatiblemultirange.
-- --
-- table functions -- table functions
-- --
......
...@@ -126,6 +126,54 @@ select x, pg_typeof(x), y, pg_typeof(y) ...@@ -126,6 +126,54 @@ select x, pg_typeof(x), y, pg_typeof(y)
drop function polyf(a anyelement, b anyarray, drop function polyf(a anyelement, b anyarray,
c anycompatible, d anycompatible); c anycompatible, d anycompatible);
create function polyf(anyrange) returns anymultirange
as 'select multirange($1);' language sql;
select polyf(int4range(1,10));
select polyf(null);
drop function polyf(anyrange);
create function polyf(anymultirange) returns anyelement
as 'select lower($1);' language sql;
select polyf(int4multirange(int4range(1,10), int4range(20,30)));
select polyf(null);
drop function polyf(anymultirange);
create function polyf(anycompatiblerange) returns anycompatiblemultirange
as 'select multirange($1);' language sql;
select polyf(int4range(1,10));
select polyf(null);
drop function polyf(anycompatiblerange);
create function polyf(anymultirange) returns anyrange
as 'select range_merge($1);' language sql;
select polyf(int4multirange(int4range(1,10), int4range(20,30)));
select polyf(null);
drop function polyf(anymultirange);
create function polyf(anycompatiblemultirange) returns anycompatiblerange
as 'select range_merge($1);' language sql;
select polyf(int4multirange(int4range(1,10), int4range(20,30)));
select polyf(null);
drop function polyf(anycompatiblemultirange);
create function polyf(anycompatiblemultirange) returns anycompatible
as 'select lower($1);' language sql;
select polyf(int4multirange(int4range(1,10), int4range(20,30)));
select polyf(null);
drop function polyf(anycompatiblemultirange);
-- --
-- Polymorphic aggregate tests -- Polymorphic aggregate tests
......
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