2020-03-17 19:54:46 +01:00
|
|
|
--
|
|
|
|
-- Tests for polymorphic SQL functions and aggregates based on them.
|
2009-10-08 04:39:25 +02:00
|
|
|
-- Tests for other features related to function-calling have snuck in, too.
|
2020-03-17 19:54:46 +01:00
|
|
|
--
|
|
|
|
create function polyf(x anyelement) returns anyelement as $$
|
|
|
|
select x + 1
|
|
|
|
$$ language sql;
|
|
|
|
select polyf(42) as int, polyf(4.5) as num;
|
|
|
|
int | num
|
|
|
|
-----+-----
|
|
|
|
43 | 5.5
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select polyf(point(3,4)); -- fail for lack of + operator
|
|
|
|
ERROR: operator does not exist: point + integer
|
|
|
|
LINE 2: select x + 1
|
|
|
|
^
|
|
|
|
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
|
|
|
|
QUERY:
|
|
|
|
select x + 1
|
|
|
|
|
|
|
|
CONTEXT: SQL function "polyf" during inlining
|
|
|
|
drop function polyf(x anyelement);
|
|
|
|
create function polyf(x anyelement) returns anyarray as $$
|
|
|
|
select array[x + 1, x + 2]
|
|
|
|
$$ language sql;
|
|
|
|
select polyf(42) as int, polyf(4.5) as num;
|
|
|
|
int | num
|
|
|
|
---------+-----------
|
|
|
|
{43,44} | {5.5,6.5}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
drop function polyf(x anyelement);
|
|
|
|
create function polyf(x anyarray) returns anyelement as $$
|
|
|
|
select x[1]
|
|
|
|
$$ language sql;
|
|
|
|
select polyf(array[2,4]) as int, polyf(array[4.5, 7.7]) as num;
|
|
|
|
int | num
|
|
|
|
-----+-----
|
|
|
|
2 | 4.5
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select polyf(stavalues1) from pg_statistic; -- fail, can't infer element type
|
Adjust handling of an ANYARRAY actual input for an ANYARRAY argument.
Ordinarily it's impossible for an actual input of a function to have
declared type ANYARRAY, since we'd resolve that to a concrete array
type before doing argument type resolution for the function. But an
exception arises for functions applied to certain columns of pg_statistic
or pg_stats, since we abuse the "anyarray" pseudotype by using it to
declare those columns. So parse_coerce.c has to deal with the case.
Previously we allowed an ANYARRAY actual input to match an ANYARRAY
polymorphic argument, but only if no other argument or result was
declared ANYELEMENT. When that logic was written, those were the only
two polymorphic types, and I fear nobody thought carefully about how it
ought to extend to the other ones that came along later. But actually
it was wrong even then, because if a function has two ANYARRAY
arguments, it should be able to expect that they have identical element
types, and we'd not be able to ensure that.
The correct generalization is that we can match an ANYARRAY actual input
to an ANYARRAY polymorphic argument only if no other argument or result
is of any polymorphic type, so that no promises are being made about
element type compatibility. check_generic_type_consistency can't test
that condition, but it seems better anyway to accept such matches there
and then throw an error if needed in enforce_generic_type_consistency.
That way we can produce a specific error message rather than an
unintuitive "function does not exist" complaint. (There's some risk
perhaps of getting new ambiguous-function complaints, but I think that
any set of functions for which that could happen would be ambiguous
against ordinary array columns as well.) While we're at it, we can
improve the message that's produced in cases that the code did already
object to, as shown in the regression test changes.
Also, remove a similar test that got cargo-culted in for ANYRANGE;
there are no catalog columns of type ANYRANGE, and I hope we never
create any, so that's not needed. (It was incomplete anyway.)
While here, update some comments and rearrange the code a bit in
preparation for upcoming additions of more polymorphic types.
In practical situations I believe this is just exchanging one error
message for another, hopefully better, one. So it doesn't seem
needful to back-patch, even though the mistake is ancient.
Discussion: https://postgr.es/m/21569.1584314271@sss.pgh.pa.us
2020-03-17 23:29:07 +01:00
|
|
|
ERROR: cannot determine element type of "anyarray" argument
|
2020-03-17 19:54:46 +01:00
|
|
|
drop function polyf(x anyarray);
|
|
|
|
create function polyf(x anyarray) returns anyarray as $$
|
|
|
|
select x
|
|
|
|
$$ language sql;
|
|
|
|
select polyf(array[2,4]) as int, polyf(array[4.5, 7.7]) as num;
|
|
|
|
int | num
|
|
|
|
-------+-----------
|
|
|
|
{2,4} | {4.5,7.7}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select polyf(stavalues1) from pg_statistic; -- fail, can't infer element type
|
|
|
|
ERROR: return type anyarray is not supported for SQL functions
|
|
|
|
CONTEXT: SQL function "polyf" during inlining
|
|
|
|
drop function polyf(x anyarray);
|
|
|
|
-- fail, can't infer type:
|
|
|
|
create function polyf(x anyelement) returns anyrange as $$
|
|
|
|
select array[x + 1, x + 2]
|
|
|
|
$$ language sql;
|
|
|
|
ERROR: cannot determine result data type
|
Multirange datatypes
Multiranges are basically sorted arrays of non-overlapping ranges with
set-theoretic operations defined over them.
Since v14, each range type automatically gets a corresponding multirange
datatype. There are both manual and automatic mechanisms for naming multirange
types. Once can specify multirange type name using multirange_type_name
attribute in CREATE TYPE. Otherwise, a multirange type name is generated
automatically. If the range type name contains "range" then we change that to
"multirange". Otherwise, we add "_multirange" to the end.
Implementation of multiranges comes with a space-efficient internal
representation format, which evades extra paddings and duplicated storage of
oids. Altogether this format allows fetching a particular range by its index
in O(n).
Statistic gathering and selectivity estimation are implemented for multiranges.
For this purpose, stored multirange is approximated as union range without gaps.
This field will likely need improvements in the future.
Catversion is bumped.
Discussion: https://postgr.es/m/CALNJ-vSUpQ_Y%3DjXvTxt1VYFztaBSsWVXeF1y6gTYQ4bOiWDLgQ%40mail.gmail.com
Discussion: https://postgr.es/m/a0b8026459d1e6167933be2104a6174e7d40d0ab.camel%40j-davis.com#fe7218c83b08068bfffb0c5293eceda0
Author: Paul Jungwirth, revised by me
Reviewed-by: David Fetter, Corey Huinker, Jeff Davis, Pavel Stehule
Reviewed-by: Alvaro Herrera, Tom Lane, Isaac Morland, David G. Johnston
Reviewed-by: Zhihong Yu, Alexander Korotkov
2020-12-20 05:20:33 +01:00
|
|
|
DETAIL: A result of type anyrange requires at least one input of type anyrange or anymultirange.
|
2020-03-17 19:54:46 +01:00
|
|
|
create function polyf(x anyrange) returns anyarray as $$
|
|
|
|
select array[lower(x), upper(x)]
|
|
|
|
$$ language sql;
|
|
|
|
select polyf(int4range(42, 49)) as int, polyf(float8range(4.5, 7.8)) as num;
|
|
|
|
int | num
|
|
|
|
---------+-----------
|
|
|
|
{42,49} | {4.5,7.8}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
drop function polyf(x anyrange);
|
Introduce "anycompatible" family of polymorphic types.
This patch adds the pseudo-types anycompatible, anycompatiblearray,
anycompatiblenonarray, and anycompatiblerange. They work much like
anyelement, anyarray, anynonarray, and anyrange respectively, except
that the actual input values need not match precisely in type.
Instead, if we can find a common supertype (using the same rules
as for UNION/CASE type resolution), then the parser automatically
promotes the input values to that type. For example,
"myfunc(anycompatible, anycompatible)" can match a call with one
integer and one bigint argument, with the integer automatically
promoted to bigint. With anyelement in the definition, the user
would have had to cast the integer explicitly.
The new types also provide a second, independent set of type variables
for function matching; thus with "myfunc(anyelement, anyelement,
anycompatible) returns anycompatible" the first two arguments are
constrained to be the same type, but the third can be some other
type, and the result has the type of the third argument. The need
for more than one set of type variables was foreseen back when we
first invented the polymorphic types, but we never did anything
about it.
Pavel Stehule, revised a bit by me
Discussion: https://postgr.es/m/CAFj8pRDna7VqNi8gR+Tt2Ktmz0cq5G93guc3Sbn_NVPLdXAkqA@mail.gmail.com
2020-03-19 16:43:11 +01:00
|
|
|
create function polyf(x anycompatible, y anycompatible) returns anycompatiblearray as $$
|
|
|
|
select array[x, y]
|
|
|
|
$$ language sql;
|
|
|
|
select polyf(2, 4) as int, polyf(2, 4.5) as num;
|
|
|
|
int | num
|
|
|
|
-------+---------
|
|
|
|
{2,4} | {2,4.5}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
drop function polyf(x anycompatible, y anycompatible);
|
|
|
|
create function polyf(x anycompatiblerange, y anycompatible, z anycompatible) returns anycompatiblearray as $$
|
|
|
|
select array[lower(x), upper(x), y, z]
|
|
|
|
$$ language sql;
|
|
|
|
select polyf(int4range(42, 49), 11, 2::smallint) as int, polyf(float8range(4.5, 7.8), 7.8, 11::real) as num;
|
|
|
|
int | num
|
|
|
|
--------------+------------------
|
|
|
|
{42,49,11,2} | {4.5,7.8,7.8,11}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select polyf(int4range(42, 49), 11, 4.5) as fail; -- range type doesn't fit
|
|
|
|
ERROR: function polyf(int4range, integer, numeric) does not exist
|
|
|
|
LINE 1: select polyf(int4range(42, 49), 11, 4.5) as fail;
|
|
|
|
^
|
|
|
|
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
|
|
|
|
drop function polyf(x anycompatiblerange, y anycompatible, z anycompatible);
|
Multirange datatypes
Multiranges are basically sorted arrays of non-overlapping ranges with
set-theoretic operations defined over them.
Since v14, each range type automatically gets a corresponding multirange
datatype. There are both manual and automatic mechanisms for naming multirange
types. Once can specify multirange type name using multirange_type_name
attribute in CREATE TYPE. Otherwise, a multirange type name is generated
automatically. If the range type name contains "range" then we change that to
"multirange". Otherwise, we add "_multirange" to the end.
Implementation of multiranges comes with a space-efficient internal
representation format, which evades extra paddings and duplicated storage of
oids. Altogether this format allows fetching a particular range by its index
in O(n).
Statistic gathering and selectivity estimation are implemented for multiranges.
For this purpose, stored multirange is approximated as union range without gaps.
This field will likely need improvements in the future.
Catversion is bumped.
Discussion: https://postgr.es/m/CALNJ-vSUpQ_Y%3DjXvTxt1VYFztaBSsWVXeF1y6gTYQ4bOiWDLgQ%40mail.gmail.com
Discussion: https://postgr.es/m/a0b8026459d1e6167933be2104a6174e7d40d0ab.camel%40j-davis.com#fe7218c83b08068bfffb0c5293eceda0
Author: Paul Jungwirth, revised by me
Reviewed-by: David Fetter, Corey Huinker, Jeff Davis, Pavel Stehule
Reviewed-by: Alvaro Herrera, Tom Lane, Isaac Morland, David G. Johnston
Reviewed-by: Zhihong Yu, Alexander Korotkov
2020-12-20 05:20:33 +01:00
|
|
|
create function polyf(x anycompatiblemultirange, y anycompatible, z anycompatible) returns anycompatiblearray as $$
|
|
|
|
select array[lower(x), upper(x), y, z]
|
|
|
|
$$ language sql;
|
|
|
|
select polyf(multirange(int4range(42, 49)), 11, 2::smallint) as int, polyf(multirange(float8range(4.5, 7.8)), 7.8, 11::real) as num;
|
|
|
|
int | num
|
|
|
|
--------------+------------------
|
|
|
|
{42,49,11,2} | {4.5,7.8,7.8,11}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select polyf(multirange(int4range(42, 49)), 11, 4.5) as fail; -- range type doesn't fit
|
|
|
|
ERROR: function polyf(int4multirange, integer, numeric) does not exist
|
|
|
|
LINE 1: select polyf(multirange(int4range(42, 49)), 11, 4.5) as fail...
|
|
|
|
^
|
|
|
|
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
|
|
|
|
drop function polyf(x anycompatiblemultirange, y anycompatible, z anycompatible);
|
Introduce "anycompatible" family of polymorphic types.
This patch adds the pseudo-types anycompatible, anycompatiblearray,
anycompatiblenonarray, and anycompatiblerange. They work much like
anyelement, anyarray, anynonarray, and anyrange respectively, except
that the actual input values need not match precisely in type.
Instead, if we can find a common supertype (using the same rules
as for UNION/CASE type resolution), then the parser automatically
promotes the input values to that type. For example,
"myfunc(anycompatible, anycompatible)" can match a call with one
integer and one bigint argument, with the integer automatically
promoted to bigint. With anyelement in the definition, the user
would have had to cast the integer explicitly.
The new types also provide a second, independent set of type variables
for function matching; thus with "myfunc(anyelement, anyelement,
anycompatible) returns anycompatible" the first two arguments are
constrained to be the same type, but the third can be some other
type, and the result has the type of the third argument. The need
for more than one set of type variables was foreseen back when we
first invented the polymorphic types, but we never did anything
about it.
Pavel Stehule, revised a bit by me
Discussion: https://postgr.es/m/CAFj8pRDna7VqNi8gR+Tt2Ktmz0cq5G93guc3Sbn_NVPLdXAkqA@mail.gmail.com
2020-03-19 16:43:11 +01:00
|
|
|
-- fail, can't infer type:
|
|
|
|
create function polyf(x anycompatible) returns anycompatiblerange as $$
|
|
|
|
select array[x + 1, x + 2]
|
|
|
|
$$ language sql;
|
|
|
|
ERROR: cannot determine result data type
|
Multirange datatypes
Multiranges are basically sorted arrays of non-overlapping ranges with
set-theoretic operations defined over them.
Since v14, each range type automatically gets a corresponding multirange
datatype. There are both manual and automatic mechanisms for naming multirange
types. Once can specify multirange type name using multirange_type_name
attribute in CREATE TYPE. Otherwise, a multirange type name is generated
automatically. If the range type name contains "range" then we change that to
"multirange". Otherwise, we add "_multirange" to the end.
Implementation of multiranges comes with a space-efficient internal
representation format, which evades extra paddings and duplicated storage of
oids. Altogether this format allows fetching a particular range by its index
in O(n).
Statistic gathering and selectivity estimation are implemented for multiranges.
For this purpose, stored multirange is approximated as union range without gaps.
This field will likely need improvements in the future.
Catversion is bumped.
Discussion: https://postgr.es/m/CALNJ-vSUpQ_Y%3DjXvTxt1VYFztaBSsWVXeF1y6gTYQ4bOiWDLgQ%40mail.gmail.com
Discussion: https://postgr.es/m/a0b8026459d1e6167933be2104a6174e7d40d0ab.camel%40j-davis.com#fe7218c83b08068bfffb0c5293eceda0
Author: Paul Jungwirth, revised by me
Reviewed-by: David Fetter, Corey Huinker, Jeff Davis, Pavel Stehule
Reviewed-by: Alvaro Herrera, Tom Lane, Isaac Morland, David G. Johnston
Reviewed-by: Zhihong Yu, Alexander Korotkov
2020-12-20 05:20:33 +01:00
|
|
|
DETAIL: A result of type anycompatiblerange requires at least one input of type anycompatiblerange or anycompatiblemultirange.
|
Introduce "anycompatible" family of polymorphic types.
This patch adds the pseudo-types anycompatible, anycompatiblearray,
anycompatiblenonarray, and anycompatiblerange. They work much like
anyelement, anyarray, anynonarray, and anyrange respectively, except
that the actual input values need not match precisely in type.
Instead, if we can find a common supertype (using the same rules
as for UNION/CASE type resolution), then the parser automatically
promotes the input values to that type. For example,
"myfunc(anycompatible, anycompatible)" can match a call with one
integer and one bigint argument, with the integer automatically
promoted to bigint. With anyelement in the definition, the user
would have had to cast the integer explicitly.
The new types also provide a second, independent set of type variables
for function matching; thus with "myfunc(anyelement, anyelement,
anycompatible) returns anycompatible" the first two arguments are
constrained to be the same type, but the third can be some other
type, and the result has the type of the third argument. The need
for more than one set of type variables was foreseen back when we
first invented the polymorphic types, but we never did anything
about it.
Pavel Stehule, revised a bit by me
Discussion: https://postgr.es/m/CAFj8pRDna7VqNi8gR+Tt2Ktmz0cq5G93guc3Sbn_NVPLdXAkqA@mail.gmail.com
2020-03-19 16:43:11 +01:00
|
|
|
create function polyf(x anycompatiblerange, y anycompatiblearray) returns anycompatiblerange as $$
|
|
|
|
select x
|
|
|
|
$$ language sql;
|
|
|
|
select polyf(int4range(42, 49), array[11]) as int, polyf(float8range(4.5, 7.8), array[7]) as num;
|
|
|
|
int | num
|
|
|
|
---------+-----------
|
|
|
|
[42,49) | [4.5,7.8)
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
drop function polyf(x anycompatiblerange, y anycompatiblearray);
|
Multirange datatypes
Multiranges are basically sorted arrays of non-overlapping ranges with
set-theoretic operations defined over them.
Since v14, each range type automatically gets a corresponding multirange
datatype. There are both manual and automatic mechanisms for naming multirange
types. Once can specify multirange type name using multirange_type_name
attribute in CREATE TYPE. Otherwise, a multirange type name is generated
automatically. If the range type name contains "range" then we change that to
"multirange". Otherwise, we add "_multirange" to the end.
Implementation of multiranges comes with a space-efficient internal
representation format, which evades extra paddings and duplicated storage of
oids. Altogether this format allows fetching a particular range by its index
in O(n).
Statistic gathering and selectivity estimation are implemented for multiranges.
For this purpose, stored multirange is approximated as union range without gaps.
This field will likely need improvements in the future.
Catversion is bumped.
Discussion: https://postgr.es/m/CALNJ-vSUpQ_Y%3DjXvTxt1VYFztaBSsWVXeF1y6gTYQ4bOiWDLgQ%40mail.gmail.com
Discussion: https://postgr.es/m/a0b8026459d1e6167933be2104a6174e7d40d0ab.camel%40j-davis.com#fe7218c83b08068bfffb0c5293eceda0
Author: Paul Jungwirth, revised by me
Reviewed-by: David Fetter, Corey Huinker, Jeff Davis, Pavel Stehule
Reviewed-by: Alvaro Herrera, Tom Lane, Isaac Morland, David G. Johnston
Reviewed-by: Zhihong Yu, Alexander Korotkov
2020-12-20 05:20:33 +01:00
|
|
|
-- fail, can't infer type:
|
|
|
|
create function polyf(x anycompatible) returns anycompatiblemultirange as $$
|
|
|
|
select array[x + 1, x + 2]
|
|
|
|
$$ language sql;
|
|
|
|
ERROR: cannot determine result data type
|
|
|
|
DETAIL: A result of type anycompatiblemultirange requires at least one input of type anycompatiblerange or anycompatiblemultirange.
|
|
|
|
create function polyf(x anycompatiblemultirange, y anycompatiblearray) returns anycompatiblemultirange as $$
|
|
|
|
select x
|
|
|
|
$$ language sql;
|
|
|
|
select polyf(multirange(int4range(42, 49)), array[11]) as int, polyf(multirange(float8range(4.5, 7.8)), array[7]) as num;
|
|
|
|
int | num
|
|
|
|
-----------+-------------
|
|
|
|
{[42,49)} | {[4.5,7.8)}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
drop function polyf(x anycompatiblemultirange, y anycompatiblearray);
|
Introduce "anycompatible" family of polymorphic types.
This patch adds the pseudo-types anycompatible, anycompatiblearray,
anycompatiblenonarray, and anycompatiblerange. They work much like
anyelement, anyarray, anynonarray, and anyrange respectively, except
that the actual input values need not match precisely in type.
Instead, if we can find a common supertype (using the same rules
as for UNION/CASE type resolution), then the parser automatically
promotes the input values to that type. For example,
"myfunc(anycompatible, anycompatible)" can match a call with one
integer and one bigint argument, with the integer automatically
promoted to bigint. With anyelement in the definition, the user
would have had to cast the integer explicitly.
The new types also provide a second, independent set of type variables
for function matching; thus with "myfunc(anyelement, anyelement,
anycompatible) returns anycompatible" the first two arguments are
constrained to be the same type, but the third can be some other
type, and the result has the type of the third argument. The need
for more than one set of type variables was foreseen back when we
first invented the polymorphic types, but we never did anything
about it.
Pavel Stehule, revised a bit by me
Discussion: https://postgr.es/m/CAFj8pRDna7VqNi8gR+Tt2Ktmz0cq5G93guc3Sbn_NVPLdXAkqA@mail.gmail.com
2020-03-19 16:43:11 +01:00
|
|
|
create function polyf(a anyelement, b anyarray,
|
|
|
|
c anycompatible, d anycompatible,
|
|
|
|
OUT x anyarray, OUT y anycompatiblearray)
|
|
|
|
as $$
|
|
|
|
select a || b, array[c, d]
|
|
|
|
$$ language sql;
|
|
|
|
select x, pg_typeof(x), y, pg_typeof(y)
|
|
|
|
from polyf(11, array[1, 2], 42, 34.5);
|
|
|
|
x | pg_typeof | y | pg_typeof
|
|
|
|
----------+-----------+-----------+-----------
|
|
|
|
{11,1,2} | integer[] | {42,34.5} | numeric[]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x), y, pg_typeof(y)
|
|
|
|
from polyf(11, array[1, 2], point(1,2), point(3,4));
|
|
|
|
x | pg_typeof | y | pg_typeof
|
|
|
|
----------+-----------+-------------------+-----------
|
|
|
|
{11,1,2} | integer[] | {"(1,2)","(3,4)"} | point[]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x), y, pg_typeof(y)
|
|
|
|
from polyf(11, '{1,2}', point(1,2), '(3,4)');
|
|
|
|
x | pg_typeof | y | pg_typeof
|
|
|
|
----------+-----------+-------------------+-----------
|
|
|
|
{11,1,2} | integer[] | {"(1,2)","(3,4)"} | point[]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x), y, pg_typeof(y)
|
|
|
|
from polyf(11, array[1, 2.2], 42, 34.5); -- fail
|
|
|
|
ERROR: function polyf(integer, numeric[], integer, numeric) does not exist
|
|
|
|
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.
|
|
|
|
drop function polyf(a anyelement, b anyarray,
|
|
|
|
c anycompatible, d anycompatible);
|
2021-07-27 21:01:49 +02:00
|
|
|
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);
|
2020-03-17 19:54:46 +01:00
|
|
|
--
|
|
|
|
-- Polymorphic aggregate tests
|
|
|
|
--
|
2003-07-01 21:10:53 +02:00
|
|
|
-- Legend:
|
|
|
|
-----------
|
|
|
|
-- A = type is ANY
|
|
|
|
-- P = type is polymorphic
|
|
|
|
-- N = type is non-polymorphic
|
|
|
|
-- B = aggregate base type
|
|
|
|
-- S = aggregate state type
|
|
|
|
-- R = aggregate return type
|
|
|
|
-- 1 = arg1 of a function
|
|
|
|
-- 2 = arg2 of a function
|
|
|
|
-- ag = aggregate
|
|
|
|
-- tf = trans (state) function
|
|
|
|
-- ff = final function
|
|
|
|
-- rt = return type of a function
|
|
|
|
-- -> = implies
|
|
|
|
-- => = allowed
|
|
|
|
-- !> = not allowed
|
|
|
|
-- E = exists
|
|
|
|
-- NE = not-exists
|
2009-10-08 04:39:25 +02:00
|
|
|
--
|
2003-07-01 21:10:53 +02:00
|
|
|
-- Possible states:
|
|
|
|
-- ----------------
|
|
|
|
-- B = (A || P || N)
|
|
|
|
-- when (B = A) -> (tf2 = NE)
|
|
|
|
-- S = (P || N)
|
|
|
|
-- ff = (E || NE)
|
|
|
|
-- tf1 = (P || N)
|
|
|
|
-- tf2 = (NE || P || N)
|
|
|
|
-- R = (P || N)
|
|
|
|
-- create functions for use as tf and ff with the needed combinations of
|
|
|
|
-- argument polymorphism, but within the constraints of valid aggregate
|
|
|
|
-- functions, i.e. tf arg1 and tf return type must match
|
|
|
|
-- polymorphic single arg transfn
|
2006-02-27 17:09:50 +01:00
|
|
|
CREATE FUNCTION stfp(anyarray) RETURNS anyarray AS
|
|
|
|
'select $1' LANGUAGE SQL;
|
2003-07-01 21:10:53 +02:00
|
|
|
-- non-polymorphic single arg transfn
|
2006-02-27 17:09:50 +01:00
|
|
|
CREATE FUNCTION stfnp(int[]) RETURNS int[] AS
|
|
|
|
'select $1' LANGUAGE SQL;
|
2003-07-01 21:10:53 +02:00
|
|
|
-- dual polymorphic transfn
|
2006-02-27 17:09:50 +01:00
|
|
|
CREATE FUNCTION tfp(anyarray,anyelement) RETURNS anyarray AS
|
|
|
|
'select $1 || $2' LANGUAGE SQL;
|
2003-07-01 21:10:53 +02:00
|
|
|
-- dual non-polymorphic transfn
|
2006-02-27 17:09:50 +01:00
|
|
|
CREATE FUNCTION tfnp(int[],int) RETURNS int[] AS
|
|
|
|
'select $1 || $2' LANGUAGE SQL;
|
2003-07-01 21:10:53 +02:00
|
|
|
-- arg1 only polymorphic transfn
|
2006-02-27 17:09:50 +01:00
|
|
|
CREATE FUNCTION tf1p(anyarray,int) RETURNS anyarray AS
|
|
|
|
'select $1' LANGUAGE SQL;
|
2003-07-01 21:10:53 +02:00
|
|
|
-- arg2 only polymorphic transfn
|
2006-02-27 17:09:50 +01:00
|
|
|
CREATE FUNCTION tf2p(int[],anyelement) RETURNS int[] AS
|
|
|
|
'select $1' LANGUAGE SQL;
|
2006-07-27 21:52:07 +02:00
|
|
|
-- multi-arg polymorphic
|
|
|
|
CREATE FUNCTION sum3(anyelement,anyelement,anyelement) returns anyelement AS
|
|
|
|
'select $1+$2+$3' language sql strict;
|
2003-07-01 21:10:53 +02:00
|
|
|
-- finalfn polymorphic
|
2006-02-27 17:09:50 +01:00
|
|
|
CREATE FUNCTION ffp(anyarray) RETURNS anyarray AS
|
|
|
|
'select $1' LANGUAGE SQL;
|
2003-07-01 21:10:53 +02:00
|
|
|
-- finalfn non-polymorphic
|
|
|
|
CREATE FUNCTION ffnp(int[]) returns int[] as
|
2006-02-27 17:09:50 +01:00
|
|
|
'select $1' LANGUAGE SQL;
|
2003-07-01 21:10:53 +02:00
|
|
|
-- Try to cover all the possible states:
|
2009-10-08 04:39:25 +02:00
|
|
|
--
|
2003-07-01 21:10:53 +02:00
|
|
|
-- Note: in Cases 1 & 2, we are trying to return P. Therefore, if the transfn
|
|
|
|
-- is stfnp, tfnp, or tf2p, we must use ffp as finalfn, because stfnp, tfnp,
|
|
|
|
-- and tf2p do not return P. Conversely, in Cases 3 & 4, we are trying to
|
|
|
|
-- return N. Therefore, if the transfn is stfp, tfp, or tf1p, we must use ffnp
|
|
|
|
-- as finalfn, because stfp, tfp, and tf1p do not return N.
|
|
|
|
--
|
|
|
|
-- Case1 (R = P) && (B = A)
|
|
|
|
-- ------------------------
|
|
|
|
-- S tf1
|
|
|
|
-- -------
|
|
|
|
-- N N
|
|
|
|
-- should CREATE
|
2006-07-27 21:52:07 +02:00
|
|
|
CREATE AGGREGATE myaggp01a(*) (SFUNC = stfnp, STYPE = int4[],
|
2003-07-01 21:10:53 +02:00
|
|
|
FINALFUNC = ffp, INITCOND = '{}');
|
|
|
|
-- P N
|
|
|
|
-- should ERROR: stfnp(anyarray) not matched by stfnp(int[])
|
2006-07-27 21:52:07 +02:00
|
|
|
CREATE AGGREGATE myaggp02a(*) (SFUNC = stfnp, STYPE = anyarray,
|
2003-07-01 21:10:53 +02:00
|
|
|
FINALFUNC = ffp, INITCOND = '{}');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: cannot determine transition data type
|
Multirange datatypes
Multiranges are basically sorted arrays of non-overlapping ranges with
set-theoretic operations defined over them.
Since v14, each range type automatically gets a corresponding multirange
datatype. There are both manual and automatic mechanisms for naming multirange
types. Once can specify multirange type name using multirange_type_name
attribute in CREATE TYPE. Otherwise, a multirange type name is generated
automatically. If the range type name contains "range" then we change that to
"multirange". Otherwise, we add "_multirange" to the end.
Implementation of multiranges comes with a space-efficient internal
representation format, which evades extra paddings and duplicated storage of
oids. Altogether this format allows fetching a particular range by its index
in O(n).
Statistic gathering and selectivity estimation are implemented for multiranges.
For this purpose, stored multirange is approximated as union range without gaps.
This field will likely need improvements in the future.
Catversion is bumped.
Discussion: https://postgr.es/m/CALNJ-vSUpQ_Y%3DjXvTxt1VYFztaBSsWVXeF1y6gTYQ4bOiWDLgQ%40mail.gmail.com
Discussion: https://postgr.es/m/a0b8026459d1e6167933be2104a6174e7d40d0ab.camel%40j-davis.com#fe7218c83b08068bfffb0c5293eceda0
Author: Paul Jungwirth, revised by me
Reviewed-by: David Fetter, Corey Huinker, Jeff Davis, Pavel Stehule
Reviewed-by: Alvaro Herrera, Tom Lane, Isaac Morland, David G. Johnston
Reviewed-by: Zhihong Yu, Alexander Korotkov
2020-12-20 05:20:33 +01:00
|
|
|
DETAIL: A result of type anyarray requires at least one input of type anyelement, anyarray, anynonarray, anyenum, anyrange, or anymultirange.
|
2003-07-01 21:10:53 +02:00
|
|
|
-- N P
|
|
|
|
-- should CREATE
|
2006-07-27 21:52:07 +02:00
|
|
|
CREATE AGGREGATE myaggp03a(*) (SFUNC = stfp, STYPE = int4[],
|
2003-07-01 21:10:53 +02:00
|
|
|
FINALFUNC = ffp, INITCOND = '{}');
|
2006-07-27 21:52:07 +02:00
|
|
|
CREATE AGGREGATE myaggp03b(*) (SFUNC = stfp, STYPE = int4[],
|
2003-07-01 21:10:53 +02:00
|
|
|
INITCOND = '{}');
|
|
|
|
-- P P
|
|
|
|
-- should ERROR: we have no way to resolve S
|
2006-07-27 21:52:07 +02:00
|
|
|
CREATE AGGREGATE myaggp04a(*) (SFUNC = stfp, STYPE = anyarray,
|
2003-07-01 21:10:53 +02:00
|
|
|
FINALFUNC = ffp, INITCOND = '{}');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: cannot determine transition data type
|
Multirange datatypes
Multiranges are basically sorted arrays of non-overlapping ranges with
set-theoretic operations defined over them.
Since v14, each range type automatically gets a corresponding multirange
datatype. There are both manual and automatic mechanisms for naming multirange
types. Once can specify multirange type name using multirange_type_name
attribute in CREATE TYPE. Otherwise, a multirange type name is generated
automatically. If the range type name contains "range" then we change that to
"multirange". Otherwise, we add "_multirange" to the end.
Implementation of multiranges comes with a space-efficient internal
representation format, which evades extra paddings and duplicated storage of
oids. Altogether this format allows fetching a particular range by its index
in O(n).
Statistic gathering and selectivity estimation are implemented for multiranges.
For this purpose, stored multirange is approximated as union range without gaps.
This field will likely need improvements in the future.
Catversion is bumped.
Discussion: https://postgr.es/m/CALNJ-vSUpQ_Y%3DjXvTxt1VYFztaBSsWVXeF1y6gTYQ4bOiWDLgQ%40mail.gmail.com
Discussion: https://postgr.es/m/a0b8026459d1e6167933be2104a6174e7d40d0ab.camel%40j-davis.com#fe7218c83b08068bfffb0c5293eceda0
Author: Paul Jungwirth, revised by me
Reviewed-by: David Fetter, Corey Huinker, Jeff Davis, Pavel Stehule
Reviewed-by: Alvaro Herrera, Tom Lane, Isaac Morland, David G. Johnston
Reviewed-by: Zhihong Yu, Alexander Korotkov
2020-12-20 05:20:33 +01:00
|
|
|
DETAIL: A result of type anyarray requires at least one input of type anyelement, anyarray, anynonarray, anyenum, anyrange, or anymultirange.
|
2006-07-27 21:52:07 +02:00
|
|
|
CREATE AGGREGATE myaggp04b(*) (SFUNC = stfp, STYPE = anyarray,
|
2003-07-01 21:10:53 +02:00
|
|
|
INITCOND = '{}');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: cannot determine transition data type
|
Multirange datatypes
Multiranges are basically sorted arrays of non-overlapping ranges with
set-theoretic operations defined over them.
Since v14, each range type automatically gets a corresponding multirange
datatype. There are both manual and automatic mechanisms for naming multirange
types. Once can specify multirange type name using multirange_type_name
attribute in CREATE TYPE. Otherwise, a multirange type name is generated
automatically. If the range type name contains "range" then we change that to
"multirange". Otherwise, we add "_multirange" to the end.
Implementation of multiranges comes with a space-efficient internal
representation format, which evades extra paddings and duplicated storage of
oids. Altogether this format allows fetching a particular range by its index
in O(n).
Statistic gathering and selectivity estimation are implemented for multiranges.
For this purpose, stored multirange is approximated as union range without gaps.
This field will likely need improvements in the future.
Catversion is bumped.
Discussion: https://postgr.es/m/CALNJ-vSUpQ_Y%3DjXvTxt1VYFztaBSsWVXeF1y6gTYQ4bOiWDLgQ%40mail.gmail.com
Discussion: https://postgr.es/m/a0b8026459d1e6167933be2104a6174e7d40d0ab.camel%40j-davis.com#fe7218c83b08068bfffb0c5293eceda0
Author: Paul Jungwirth, revised by me
Reviewed-by: David Fetter, Corey Huinker, Jeff Davis, Pavel Stehule
Reviewed-by: Alvaro Herrera, Tom Lane, Isaac Morland, David G. Johnston
Reviewed-by: Zhihong Yu, Alexander Korotkov
2020-12-20 05:20:33 +01:00
|
|
|
DETAIL: A result of type anyarray requires at least one input of type anyelement, anyarray, anynonarray, anyenum, anyrange, or anymultirange.
|
2003-07-01 21:10:53 +02:00
|
|
|
-- Case2 (R = P) && ((B = P) || (B = N))
|
|
|
|
-- -------------------------------------
|
|
|
|
-- S tf1 B tf2
|
|
|
|
-- -----------------------
|
|
|
|
-- N N N N
|
|
|
|
-- should CREATE
|
|
|
|
CREATE AGGREGATE myaggp05a(BASETYPE = int, SFUNC = tfnp, STYPE = int[],
|
|
|
|
FINALFUNC = ffp, INITCOND = '{}');
|
|
|
|
-- N N N P
|
|
|
|
-- should CREATE
|
|
|
|
CREATE AGGREGATE myaggp06a(BASETYPE = int, SFUNC = tf2p, STYPE = int[],
|
|
|
|
FINALFUNC = ffp, INITCOND = '{}');
|
|
|
|
-- N N P N
|
|
|
|
-- should ERROR: tfnp(int[], anyelement) not matched by tfnp(int[], int)
|
|
|
|
CREATE AGGREGATE myaggp07a(BASETYPE = anyelement, SFUNC = tfnp, STYPE = int[],
|
|
|
|
FINALFUNC = ffp, INITCOND = '{}');
|
2003-07-04 04:51:34 +02:00
|
|
|
ERROR: function tfnp(integer[], anyelement) does not exist
|
2003-07-01 21:10:53 +02:00
|
|
|
-- N N P P
|
|
|
|
-- should CREATE
|
|
|
|
CREATE AGGREGATE myaggp08a(BASETYPE = anyelement, SFUNC = tf2p, STYPE = int[],
|
|
|
|
FINALFUNC = ffp, INITCOND = '{}');
|
|
|
|
-- N P N N
|
|
|
|
-- should CREATE
|
|
|
|
CREATE AGGREGATE myaggp09a(BASETYPE = int, SFUNC = tf1p, STYPE = int[],
|
|
|
|
FINALFUNC = ffp, INITCOND = '{}');
|
|
|
|
CREATE AGGREGATE myaggp09b(BASETYPE = int, SFUNC = tf1p, STYPE = int[],
|
|
|
|
INITCOND = '{}');
|
|
|
|
-- N P N P
|
|
|
|
-- should CREATE
|
|
|
|
CREATE AGGREGATE myaggp10a(BASETYPE = int, SFUNC = tfp, STYPE = int[],
|
|
|
|
FINALFUNC = ffp, INITCOND = '{}');
|
|
|
|
CREATE AGGREGATE myaggp10b(BASETYPE = int, SFUNC = tfp, STYPE = int[],
|
|
|
|
INITCOND = '{}');
|
|
|
|
-- N P P N
|
|
|
|
-- should ERROR: tf1p(int[],anyelement) not matched by tf1p(anyarray,int)
|
|
|
|
CREATE AGGREGATE myaggp11a(BASETYPE = anyelement, SFUNC = tf1p, STYPE = int[],
|
|
|
|
FINALFUNC = ffp, INITCOND = '{}');
|
2003-07-04 04:51:34 +02:00
|
|
|
ERROR: function tf1p(integer[], anyelement) does not exist
|
2003-07-01 21:10:53 +02:00
|
|
|
CREATE AGGREGATE myaggp11b(BASETYPE = anyelement, SFUNC = tf1p, STYPE = int[],
|
|
|
|
INITCOND = '{}');
|
2003-07-04 04:51:34 +02:00
|
|
|
ERROR: function tf1p(integer[], anyelement) does not exist
|
2003-07-01 21:10:53 +02:00
|
|
|
-- N P P P
|
|
|
|
-- should ERROR: tfp(int[],anyelement) not matched by tfp(anyarray,anyelement)
|
|
|
|
CREATE AGGREGATE myaggp12a(BASETYPE = anyelement, SFUNC = tfp, STYPE = int[],
|
|
|
|
FINALFUNC = ffp, INITCOND = '{}');
|
2003-07-04 04:51:34 +02:00
|
|
|
ERROR: function tfp(integer[], anyelement) does not exist
|
2003-07-01 21:10:53 +02:00
|
|
|
CREATE AGGREGATE myaggp12b(BASETYPE = anyelement, SFUNC = tfp, STYPE = int[],
|
|
|
|
INITCOND = '{}');
|
2003-07-04 04:51:34 +02:00
|
|
|
ERROR: function tfp(integer[], anyelement) does not exist
|
2003-07-01 21:10:53 +02:00
|
|
|
-- P N N N
|
|
|
|
-- should ERROR: tfnp(anyarray, int) not matched by tfnp(int[],int)
|
|
|
|
CREATE AGGREGATE myaggp13a(BASETYPE = int, SFUNC = tfnp, STYPE = anyarray,
|
|
|
|
FINALFUNC = ffp, INITCOND = '{}');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: cannot determine transition data type
|
Multirange datatypes
Multiranges are basically sorted arrays of non-overlapping ranges with
set-theoretic operations defined over them.
Since v14, each range type automatically gets a corresponding multirange
datatype. There are both manual and automatic mechanisms for naming multirange
types. Once can specify multirange type name using multirange_type_name
attribute in CREATE TYPE. Otherwise, a multirange type name is generated
automatically. If the range type name contains "range" then we change that to
"multirange". Otherwise, we add "_multirange" to the end.
Implementation of multiranges comes with a space-efficient internal
representation format, which evades extra paddings and duplicated storage of
oids. Altogether this format allows fetching a particular range by its index
in O(n).
Statistic gathering and selectivity estimation are implemented for multiranges.
For this purpose, stored multirange is approximated as union range without gaps.
This field will likely need improvements in the future.
Catversion is bumped.
Discussion: https://postgr.es/m/CALNJ-vSUpQ_Y%3DjXvTxt1VYFztaBSsWVXeF1y6gTYQ4bOiWDLgQ%40mail.gmail.com
Discussion: https://postgr.es/m/a0b8026459d1e6167933be2104a6174e7d40d0ab.camel%40j-davis.com#fe7218c83b08068bfffb0c5293eceda0
Author: Paul Jungwirth, revised by me
Reviewed-by: David Fetter, Corey Huinker, Jeff Davis, Pavel Stehule
Reviewed-by: Alvaro Herrera, Tom Lane, Isaac Morland, David G. Johnston
Reviewed-by: Zhihong Yu, Alexander Korotkov
2020-12-20 05:20:33 +01:00
|
|
|
DETAIL: A result of type anyarray requires at least one input of type anyelement, anyarray, anynonarray, anyenum, anyrange, or anymultirange.
|
2003-07-01 21:10:53 +02:00
|
|
|
-- P N N P
|
|
|
|
-- should ERROR: tf2p(anyarray, int) not matched by tf2p(int[],anyelement)
|
|
|
|
CREATE AGGREGATE myaggp14a(BASETYPE = int, SFUNC = tf2p, STYPE = anyarray,
|
|
|
|
FINALFUNC = ffp, INITCOND = '{}');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: cannot determine transition data type
|
Multirange datatypes
Multiranges are basically sorted arrays of non-overlapping ranges with
set-theoretic operations defined over them.
Since v14, each range type automatically gets a corresponding multirange
datatype. There are both manual and automatic mechanisms for naming multirange
types. Once can specify multirange type name using multirange_type_name
attribute in CREATE TYPE. Otherwise, a multirange type name is generated
automatically. If the range type name contains "range" then we change that to
"multirange". Otherwise, we add "_multirange" to the end.
Implementation of multiranges comes with a space-efficient internal
representation format, which evades extra paddings and duplicated storage of
oids. Altogether this format allows fetching a particular range by its index
in O(n).
Statistic gathering and selectivity estimation are implemented for multiranges.
For this purpose, stored multirange is approximated as union range without gaps.
This field will likely need improvements in the future.
Catversion is bumped.
Discussion: https://postgr.es/m/CALNJ-vSUpQ_Y%3DjXvTxt1VYFztaBSsWVXeF1y6gTYQ4bOiWDLgQ%40mail.gmail.com
Discussion: https://postgr.es/m/a0b8026459d1e6167933be2104a6174e7d40d0ab.camel%40j-davis.com#fe7218c83b08068bfffb0c5293eceda0
Author: Paul Jungwirth, revised by me
Reviewed-by: David Fetter, Corey Huinker, Jeff Davis, Pavel Stehule
Reviewed-by: Alvaro Herrera, Tom Lane, Isaac Morland, David G. Johnston
Reviewed-by: Zhihong Yu, Alexander Korotkov
2020-12-20 05:20:33 +01:00
|
|
|
DETAIL: A result of type anyarray requires at least one input of type anyelement, anyarray, anynonarray, anyenum, anyrange, or anymultirange.
|
2003-07-01 21:10:53 +02:00
|
|
|
-- P N P N
|
|
|
|
-- should ERROR: tfnp(anyarray, anyelement) not matched by tfnp(int[],int)
|
|
|
|
CREATE AGGREGATE myaggp15a(BASETYPE = anyelement, SFUNC = tfnp,
|
|
|
|
STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}');
|
2003-07-04 04:51:34 +02:00
|
|
|
ERROR: function tfnp(anyarray, anyelement) does not exist
|
2003-07-01 21:10:53 +02:00
|
|
|
-- P N P P
|
|
|
|
-- should ERROR: tf2p(anyarray, anyelement) not matched by tf2p(int[],anyelement)
|
|
|
|
CREATE AGGREGATE myaggp16a(BASETYPE = anyelement, SFUNC = tf2p,
|
|
|
|
STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}');
|
2003-07-04 04:51:34 +02:00
|
|
|
ERROR: function tf2p(anyarray, anyelement) does not exist
|
2003-07-01 21:10:53 +02:00
|
|
|
-- P P N N
|
|
|
|
-- should ERROR: we have no way to resolve S
|
|
|
|
CREATE AGGREGATE myaggp17a(BASETYPE = int, SFUNC = tf1p, STYPE = anyarray,
|
|
|
|
FINALFUNC = ffp, INITCOND = '{}');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: cannot determine transition data type
|
Multirange datatypes
Multiranges are basically sorted arrays of non-overlapping ranges with
set-theoretic operations defined over them.
Since v14, each range type automatically gets a corresponding multirange
datatype. There are both manual and automatic mechanisms for naming multirange
types. Once can specify multirange type name using multirange_type_name
attribute in CREATE TYPE. Otherwise, a multirange type name is generated
automatically. If the range type name contains "range" then we change that to
"multirange". Otherwise, we add "_multirange" to the end.
Implementation of multiranges comes with a space-efficient internal
representation format, which evades extra paddings and duplicated storage of
oids. Altogether this format allows fetching a particular range by its index
in O(n).
Statistic gathering and selectivity estimation are implemented for multiranges.
For this purpose, stored multirange is approximated as union range without gaps.
This field will likely need improvements in the future.
Catversion is bumped.
Discussion: https://postgr.es/m/CALNJ-vSUpQ_Y%3DjXvTxt1VYFztaBSsWVXeF1y6gTYQ4bOiWDLgQ%40mail.gmail.com
Discussion: https://postgr.es/m/a0b8026459d1e6167933be2104a6174e7d40d0ab.camel%40j-davis.com#fe7218c83b08068bfffb0c5293eceda0
Author: Paul Jungwirth, revised by me
Reviewed-by: David Fetter, Corey Huinker, Jeff Davis, Pavel Stehule
Reviewed-by: Alvaro Herrera, Tom Lane, Isaac Morland, David G. Johnston
Reviewed-by: Zhihong Yu, Alexander Korotkov
2020-12-20 05:20:33 +01:00
|
|
|
DETAIL: A result of type anyarray requires at least one input of type anyelement, anyarray, anynonarray, anyenum, anyrange, or anymultirange.
|
2003-07-01 21:10:53 +02:00
|
|
|
CREATE AGGREGATE myaggp17b(BASETYPE = int, SFUNC = tf1p, STYPE = anyarray,
|
|
|
|
INITCOND = '{}');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: cannot determine transition data type
|
Multirange datatypes
Multiranges are basically sorted arrays of non-overlapping ranges with
set-theoretic operations defined over them.
Since v14, each range type automatically gets a corresponding multirange
datatype. There are both manual and automatic mechanisms for naming multirange
types. Once can specify multirange type name using multirange_type_name
attribute in CREATE TYPE. Otherwise, a multirange type name is generated
automatically. If the range type name contains "range" then we change that to
"multirange". Otherwise, we add "_multirange" to the end.
Implementation of multiranges comes with a space-efficient internal
representation format, which evades extra paddings and duplicated storage of
oids. Altogether this format allows fetching a particular range by its index
in O(n).
Statistic gathering and selectivity estimation are implemented for multiranges.
For this purpose, stored multirange is approximated as union range without gaps.
This field will likely need improvements in the future.
Catversion is bumped.
Discussion: https://postgr.es/m/CALNJ-vSUpQ_Y%3DjXvTxt1VYFztaBSsWVXeF1y6gTYQ4bOiWDLgQ%40mail.gmail.com
Discussion: https://postgr.es/m/a0b8026459d1e6167933be2104a6174e7d40d0ab.camel%40j-davis.com#fe7218c83b08068bfffb0c5293eceda0
Author: Paul Jungwirth, revised by me
Reviewed-by: David Fetter, Corey Huinker, Jeff Davis, Pavel Stehule
Reviewed-by: Alvaro Herrera, Tom Lane, Isaac Morland, David G. Johnston
Reviewed-by: Zhihong Yu, Alexander Korotkov
2020-12-20 05:20:33 +01:00
|
|
|
DETAIL: A result of type anyarray requires at least one input of type anyelement, anyarray, anynonarray, anyenum, anyrange, or anymultirange.
|
2003-07-01 21:10:53 +02:00
|
|
|
-- P P N P
|
|
|
|
-- should ERROR: tfp(anyarray, int) not matched by tfp(anyarray, anyelement)
|
|
|
|
CREATE AGGREGATE myaggp18a(BASETYPE = int, SFUNC = tfp, STYPE = anyarray,
|
|
|
|
FINALFUNC = ffp, INITCOND = '{}');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: cannot determine transition data type
|
Multirange datatypes
Multiranges are basically sorted arrays of non-overlapping ranges with
set-theoretic operations defined over them.
Since v14, each range type automatically gets a corresponding multirange
datatype. There are both manual and automatic mechanisms for naming multirange
types. Once can specify multirange type name using multirange_type_name
attribute in CREATE TYPE. Otherwise, a multirange type name is generated
automatically. If the range type name contains "range" then we change that to
"multirange". Otherwise, we add "_multirange" to the end.
Implementation of multiranges comes with a space-efficient internal
representation format, which evades extra paddings and duplicated storage of
oids. Altogether this format allows fetching a particular range by its index
in O(n).
Statistic gathering and selectivity estimation are implemented for multiranges.
For this purpose, stored multirange is approximated as union range without gaps.
This field will likely need improvements in the future.
Catversion is bumped.
Discussion: https://postgr.es/m/CALNJ-vSUpQ_Y%3DjXvTxt1VYFztaBSsWVXeF1y6gTYQ4bOiWDLgQ%40mail.gmail.com
Discussion: https://postgr.es/m/a0b8026459d1e6167933be2104a6174e7d40d0ab.camel%40j-davis.com#fe7218c83b08068bfffb0c5293eceda0
Author: Paul Jungwirth, revised by me
Reviewed-by: David Fetter, Corey Huinker, Jeff Davis, Pavel Stehule
Reviewed-by: Alvaro Herrera, Tom Lane, Isaac Morland, David G. Johnston
Reviewed-by: Zhihong Yu, Alexander Korotkov
2020-12-20 05:20:33 +01:00
|
|
|
DETAIL: A result of type anyarray requires at least one input of type anyelement, anyarray, anynonarray, anyenum, anyrange, or anymultirange.
|
2003-07-01 21:10:53 +02:00
|
|
|
CREATE AGGREGATE myaggp18b(BASETYPE = int, SFUNC = tfp, STYPE = anyarray,
|
|
|
|
INITCOND = '{}');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: cannot determine transition data type
|
Multirange datatypes
Multiranges are basically sorted arrays of non-overlapping ranges with
set-theoretic operations defined over them.
Since v14, each range type automatically gets a corresponding multirange
datatype. There are both manual and automatic mechanisms for naming multirange
types. Once can specify multirange type name using multirange_type_name
attribute in CREATE TYPE. Otherwise, a multirange type name is generated
automatically. If the range type name contains "range" then we change that to
"multirange". Otherwise, we add "_multirange" to the end.
Implementation of multiranges comes with a space-efficient internal
representation format, which evades extra paddings and duplicated storage of
oids. Altogether this format allows fetching a particular range by its index
in O(n).
Statistic gathering and selectivity estimation are implemented for multiranges.
For this purpose, stored multirange is approximated as union range without gaps.
This field will likely need improvements in the future.
Catversion is bumped.
Discussion: https://postgr.es/m/CALNJ-vSUpQ_Y%3DjXvTxt1VYFztaBSsWVXeF1y6gTYQ4bOiWDLgQ%40mail.gmail.com
Discussion: https://postgr.es/m/a0b8026459d1e6167933be2104a6174e7d40d0ab.camel%40j-davis.com#fe7218c83b08068bfffb0c5293eceda0
Author: Paul Jungwirth, revised by me
Reviewed-by: David Fetter, Corey Huinker, Jeff Davis, Pavel Stehule
Reviewed-by: Alvaro Herrera, Tom Lane, Isaac Morland, David G. Johnston
Reviewed-by: Zhihong Yu, Alexander Korotkov
2020-12-20 05:20:33 +01:00
|
|
|
DETAIL: A result of type anyarray requires at least one input of type anyelement, anyarray, anynonarray, anyenum, anyrange, or anymultirange.
|
2003-07-01 21:10:53 +02:00
|
|
|
-- P P P N
|
|
|
|
-- should ERROR: tf1p(anyarray, anyelement) not matched by tf1p(anyarray, int)
|
|
|
|
CREATE AGGREGATE myaggp19a(BASETYPE = anyelement, SFUNC = tf1p,
|
|
|
|
STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}');
|
2003-07-04 04:51:34 +02:00
|
|
|
ERROR: function tf1p(anyarray, anyelement) does not exist
|
2003-07-01 21:10:53 +02:00
|
|
|
CREATE AGGREGATE myaggp19b(BASETYPE = anyelement, SFUNC = tf1p,
|
|
|
|
STYPE = anyarray, INITCOND = '{}');
|
2003-07-04 04:51:34 +02:00
|
|
|
ERROR: function tf1p(anyarray, anyelement) does not exist
|
2003-07-01 21:10:53 +02:00
|
|
|
-- P P P P
|
|
|
|
-- should CREATE
|
|
|
|
CREATE AGGREGATE myaggp20a(BASETYPE = anyelement, SFUNC = tfp,
|
|
|
|
STYPE = anyarray, FINALFUNC = ffp, INITCOND = '{}');
|
|
|
|
CREATE AGGREGATE myaggp20b(BASETYPE = anyelement, SFUNC = tfp,
|
|
|
|
STYPE = anyarray, INITCOND = '{}');
|
|
|
|
-- Case3 (R = N) && (B = A)
|
|
|
|
-- ------------------------
|
|
|
|
-- S tf1
|
|
|
|
-- -------
|
|
|
|
-- N N
|
|
|
|
-- should CREATE
|
2006-07-27 21:52:07 +02:00
|
|
|
CREATE AGGREGATE myaggn01a(*) (SFUNC = stfnp, STYPE = int4[],
|
2003-07-01 21:10:53 +02:00
|
|
|
FINALFUNC = ffnp, INITCOND = '{}');
|
2006-07-27 21:52:07 +02:00
|
|
|
CREATE AGGREGATE myaggn01b(*) (SFUNC = stfnp, STYPE = int4[],
|
2003-07-01 21:10:53 +02:00
|
|
|
INITCOND = '{}');
|
|
|
|
-- P N
|
|
|
|
-- should ERROR: stfnp(anyarray) not matched by stfnp(int[])
|
2006-07-27 21:52:07 +02:00
|
|
|
CREATE AGGREGATE myaggn02a(*) (SFUNC = stfnp, STYPE = anyarray,
|
2003-07-01 21:10:53 +02:00
|
|
|
FINALFUNC = ffnp, INITCOND = '{}');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: cannot determine transition data type
|
Multirange datatypes
Multiranges are basically sorted arrays of non-overlapping ranges with
set-theoretic operations defined over them.
Since v14, each range type automatically gets a corresponding multirange
datatype. There are both manual and automatic mechanisms for naming multirange
types. Once can specify multirange type name using multirange_type_name
attribute in CREATE TYPE. Otherwise, a multirange type name is generated
automatically. If the range type name contains "range" then we change that to
"multirange". Otherwise, we add "_multirange" to the end.
Implementation of multiranges comes with a space-efficient internal
representation format, which evades extra paddings and duplicated storage of
oids. Altogether this format allows fetching a particular range by its index
in O(n).
Statistic gathering and selectivity estimation are implemented for multiranges.
For this purpose, stored multirange is approximated as union range without gaps.
This field will likely need improvements in the future.
Catversion is bumped.
Discussion: https://postgr.es/m/CALNJ-vSUpQ_Y%3DjXvTxt1VYFztaBSsWVXeF1y6gTYQ4bOiWDLgQ%40mail.gmail.com
Discussion: https://postgr.es/m/a0b8026459d1e6167933be2104a6174e7d40d0ab.camel%40j-davis.com#fe7218c83b08068bfffb0c5293eceda0
Author: Paul Jungwirth, revised by me
Reviewed-by: David Fetter, Corey Huinker, Jeff Davis, Pavel Stehule
Reviewed-by: Alvaro Herrera, Tom Lane, Isaac Morland, David G. Johnston
Reviewed-by: Zhihong Yu, Alexander Korotkov
2020-12-20 05:20:33 +01:00
|
|
|
DETAIL: A result of type anyarray requires at least one input of type anyelement, anyarray, anynonarray, anyenum, anyrange, or anymultirange.
|
2006-07-27 21:52:07 +02:00
|
|
|
CREATE AGGREGATE myaggn02b(*) (SFUNC = stfnp, STYPE = anyarray,
|
2003-07-01 21:10:53 +02:00
|
|
|
INITCOND = '{}');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: cannot determine transition data type
|
Multirange datatypes
Multiranges are basically sorted arrays of non-overlapping ranges with
set-theoretic operations defined over them.
Since v14, each range type automatically gets a corresponding multirange
datatype. There are both manual and automatic mechanisms for naming multirange
types. Once can specify multirange type name using multirange_type_name
attribute in CREATE TYPE. Otherwise, a multirange type name is generated
automatically. If the range type name contains "range" then we change that to
"multirange". Otherwise, we add "_multirange" to the end.
Implementation of multiranges comes with a space-efficient internal
representation format, which evades extra paddings and duplicated storage of
oids. Altogether this format allows fetching a particular range by its index
in O(n).
Statistic gathering and selectivity estimation are implemented for multiranges.
For this purpose, stored multirange is approximated as union range without gaps.
This field will likely need improvements in the future.
Catversion is bumped.
Discussion: https://postgr.es/m/CALNJ-vSUpQ_Y%3DjXvTxt1VYFztaBSsWVXeF1y6gTYQ4bOiWDLgQ%40mail.gmail.com
Discussion: https://postgr.es/m/a0b8026459d1e6167933be2104a6174e7d40d0ab.camel%40j-davis.com#fe7218c83b08068bfffb0c5293eceda0
Author: Paul Jungwirth, revised by me
Reviewed-by: David Fetter, Corey Huinker, Jeff Davis, Pavel Stehule
Reviewed-by: Alvaro Herrera, Tom Lane, Isaac Morland, David G. Johnston
Reviewed-by: Zhihong Yu, Alexander Korotkov
2020-12-20 05:20:33 +01:00
|
|
|
DETAIL: A result of type anyarray requires at least one input of type anyelement, anyarray, anynonarray, anyenum, anyrange, or anymultirange.
|
2003-07-01 21:10:53 +02:00
|
|
|
-- N P
|
|
|
|
-- should CREATE
|
2006-07-27 21:52:07 +02:00
|
|
|
CREATE AGGREGATE myaggn03a(*) (SFUNC = stfp, STYPE = int4[],
|
2003-07-01 21:10:53 +02:00
|
|
|
FINALFUNC = ffnp, INITCOND = '{}');
|
|
|
|
-- P P
|
|
|
|
-- should ERROR: ffnp(anyarray) not matched by ffnp(int[])
|
2006-07-27 21:52:07 +02:00
|
|
|
CREATE AGGREGATE myaggn04a(*) (SFUNC = stfp, STYPE = anyarray,
|
2003-07-01 21:10:53 +02:00
|
|
|
FINALFUNC = ffnp, INITCOND = '{}');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: cannot determine transition data type
|
Multirange datatypes
Multiranges are basically sorted arrays of non-overlapping ranges with
set-theoretic operations defined over them.
Since v14, each range type automatically gets a corresponding multirange
datatype. There are both manual and automatic mechanisms for naming multirange
types. Once can specify multirange type name using multirange_type_name
attribute in CREATE TYPE. Otherwise, a multirange type name is generated
automatically. If the range type name contains "range" then we change that to
"multirange". Otherwise, we add "_multirange" to the end.
Implementation of multiranges comes with a space-efficient internal
representation format, which evades extra paddings and duplicated storage of
oids. Altogether this format allows fetching a particular range by its index
in O(n).
Statistic gathering and selectivity estimation are implemented for multiranges.
For this purpose, stored multirange is approximated as union range without gaps.
This field will likely need improvements in the future.
Catversion is bumped.
Discussion: https://postgr.es/m/CALNJ-vSUpQ_Y%3DjXvTxt1VYFztaBSsWVXeF1y6gTYQ4bOiWDLgQ%40mail.gmail.com
Discussion: https://postgr.es/m/a0b8026459d1e6167933be2104a6174e7d40d0ab.camel%40j-davis.com#fe7218c83b08068bfffb0c5293eceda0
Author: Paul Jungwirth, revised by me
Reviewed-by: David Fetter, Corey Huinker, Jeff Davis, Pavel Stehule
Reviewed-by: Alvaro Herrera, Tom Lane, Isaac Morland, David G. Johnston
Reviewed-by: Zhihong Yu, Alexander Korotkov
2020-12-20 05:20:33 +01:00
|
|
|
DETAIL: A result of type anyarray requires at least one input of type anyelement, anyarray, anynonarray, anyenum, anyrange, or anymultirange.
|
2003-07-01 21:10:53 +02:00
|
|
|
-- Case4 (R = N) && ((B = P) || (B = N))
|
|
|
|
-- -------------------------------------
|
|
|
|
-- S tf1 B tf2
|
|
|
|
-- -----------------------
|
|
|
|
-- N N N N
|
|
|
|
-- should CREATE
|
|
|
|
CREATE AGGREGATE myaggn05a(BASETYPE = int, SFUNC = tfnp, STYPE = int[],
|
|
|
|
FINALFUNC = ffnp, INITCOND = '{}');
|
|
|
|
CREATE AGGREGATE myaggn05b(BASETYPE = int, SFUNC = tfnp, STYPE = int[],
|
|
|
|
INITCOND = '{}');
|
|
|
|
-- N N N P
|
|
|
|
-- should CREATE
|
|
|
|
CREATE AGGREGATE myaggn06a(BASETYPE = int, SFUNC = tf2p, STYPE = int[],
|
|
|
|
FINALFUNC = ffnp, INITCOND = '{}');
|
|
|
|
CREATE AGGREGATE myaggn06b(BASETYPE = int, SFUNC = tf2p, STYPE = int[],
|
|
|
|
INITCOND = '{}');
|
|
|
|
-- N N P N
|
|
|
|
-- should ERROR: tfnp(int[], anyelement) not matched by tfnp(int[], int)
|
|
|
|
CREATE AGGREGATE myaggn07a(BASETYPE = anyelement, SFUNC = tfnp, STYPE = int[],
|
|
|
|
FINALFUNC = ffnp, INITCOND = '{}');
|
2003-07-04 04:51:34 +02:00
|
|
|
ERROR: function tfnp(integer[], anyelement) does not exist
|
2003-07-01 21:10:53 +02:00
|
|
|
CREATE AGGREGATE myaggn07b(BASETYPE = anyelement, SFUNC = tfnp, STYPE = int[],
|
|
|
|
INITCOND = '{}');
|
2003-07-04 04:51:34 +02:00
|
|
|
ERROR: function tfnp(integer[], anyelement) does not exist
|
2003-07-01 21:10:53 +02:00
|
|
|
-- N N P P
|
|
|
|
-- should CREATE
|
|
|
|
CREATE AGGREGATE myaggn08a(BASETYPE = anyelement, SFUNC = tf2p, STYPE = int[],
|
|
|
|
FINALFUNC = ffnp, INITCOND = '{}');
|
|
|
|
CREATE AGGREGATE myaggn08b(BASETYPE = anyelement, SFUNC = tf2p, STYPE = int[],
|
|
|
|
INITCOND = '{}');
|
|
|
|
-- N P N N
|
|
|
|
-- should CREATE
|
|
|
|
CREATE AGGREGATE myaggn09a(BASETYPE = int, SFUNC = tf1p, STYPE = int[],
|
|
|
|
FINALFUNC = ffnp, INITCOND = '{}');
|
|
|
|
-- N P N P
|
|
|
|
-- should CREATE
|
|
|
|
CREATE AGGREGATE myaggn10a(BASETYPE = int, SFUNC = tfp, STYPE = int[],
|
|
|
|
FINALFUNC = ffnp, INITCOND = '{}');
|
|
|
|
-- N P P N
|
|
|
|
-- should ERROR: tf1p(int[],anyelement) not matched by tf1p(anyarray,int)
|
|
|
|
CREATE AGGREGATE myaggn11a(BASETYPE = anyelement, SFUNC = tf1p, STYPE = int[],
|
|
|
|
FINALFUNC = ffnp, INITCOND = '{}');
|
2003-07-04 04:51:34 +02:00
|
|
|
ERROR: function tf1p(integer[], anyelement) does not exist
|
2003-07-01 21:10:53 +02:00
|
|
|
-- N P P P
|
|
|
|
-- should ERROR: tfp(int[],anyelement) not matched by tfp(anyarray,anyelement)
|
|
|
|
CREATE AGGREGATE myaggn12a(BASETYPE = anyelement, SFUNC = tfp, STYPE = int[],
|
|
|
|
FINALFUNC = ffnp, INITCOND = '{}');
|
2003-07-04 04:51:34 +02:00
|
|
|
ERROR: function tfp(integer[], anyelement) does not exist
|
2003-07-01 21:10:53 +02:00
|
|
|
-- P N N N
|
|
|
|
-- should ERROR: tfnp(anyarray, int) not matched by tfnp(int[],int)
|
|
|
|
CREATE AGGREGATE myaggn13a(BASETYPE = int, SFUNC = tfnp, STYPE = anyarray,
|
|
|
|
FINALFUNC = ffnp, INITCOND = '{}');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: cannot determine transition data type
|
Multirange datatypes
Multiranges are basically sorted arrays of non-overlapping ranges with
set-theoretic operations defined over them.
Since v14, each range type automatically gets a corresponding multirange
datatype. There are both manual and automatic mechanisms for naming multirange
types. Once can specify multirange type name using multirange_type_name
attribute in CREATE TYPE. Otherwise, a multirange type name is generated
automatically. If the range type name contains "range" then we change that to
"multirange". Otherwise, we add "_multirange" to the end.
Implementation of multiranges comes with a space-efficient internal
representation format, which evades extra paddings and duplicated storage of
oids. Altogether this format allows fetching a particular range by its index
in O(n).
Statistic gathering and selectivity estimation are implemented for multiranges.
For this purpose, stored multirange is approximated as union range without gaps.
This field will likely need improvements in the future.
Catversion is bumped.
Discussion: https://postgr.es/m/CALNJ-vSUpQ_Y%3DjXvTxt1VYFztaBSsWVXeF1y6gTYQ4bOiWDLgQ%40mail.gmail.com
Discussion: https://postgr.es/m/a0b8026459d1e6167933be2104a6174e7d40d0ab.camel%40j-davis.com#fe7218c83b08068bfffb0c5293eceda0
Author: Paul Jungwirth, revised by me
Reviewed-by: David Fetter, Corey Huinker, Jeff Davis, Pavel Stehule
Reviewed-by: Alvaro Herrera, Tom Lane, Isaac Morland, David G. Johnston
Reviewed-by: Zhihong Yu, Alexander Korotkov
2020-12-20 05:20:33 +01:00
|
|
|
DETAIL: A result of type anyarray requires at least one input of type anyelement, anyarray, anynonarray, anyenum, anyrange, or anymultirange.
|
2003-07-01 21:10:53 +02:00
|
|
|
CREATE AGGREGATE myaggn13b(BASETYPE = int, SFUNC = tfnp, STYPE = anyarray,
|
|
|
|
INITCOND = '{}');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: cannot determine transition data type
|
Multirange datatypes
Multiranges are basically sorted arrays of non-overlapping ranges with
set-theoretic operations defined over them.
Since v14, each range type automatically gets a corresponding multirange
datatype. There are both manual and automatic mechanisms for naming multirange
types. Once can specify multirange type name using multirange_type_name
attribute in CREATE TYPE. Otherwise, a multirange type name is generated
automatically. If the range type name contains "range" then we change that to
"multirange". Otherwise, we add "_multirange" to the end.
Implementation of multiranges comes with a space-efficient internal
representation format, which evades extra paddings and duplicated storage of
oids. Altogether this format allows fetching a particular range by its index
in O(n).
Statistic gathering and selectivity estimation are implemented for multiranges.
For this purpose, stored multirange is approximated as union range without gaps.
This field will likely need improvements in the future.
Catversion is bumped.
Discussion: https://postgr.es/m/CALNJ-vSUpQ_Y%3DjXvTxt1VYFztaBSsWVXeF1y6gTYQ4bOiWDLgQ%40mail.gmail.com
Discussion: https://postgr.es/m/a0b8026459d1e6167933be2104a6174e7d40d0ab.camel%40j-davis.com#fe7218c83b08068bfffb0c5293eceda0
Author: Paul Jungwirth, revised by me
Reviewed-by: David Fetter, Corey Huinker, Jeff Davis, Pavel Stehule
Reviewed-by: Alvaro Herrera, Tom Lane, Isaac Morland, David G. Johnston
Reviewed-by: Zhihong Yu, Alexander Korotkov
2020-12-20 05:20:33 +01:00
|
|
|
DETAIL: A result of type anyarray requires at least one input of type anyelement, anyarray, anynonarray, anyenum, anyrange, or anymultirange.
|
2003-07-01 21:10:53 +02:00
|
|
|
-- P N N P
|
|
|
|
-- should ERROR: tf2p(anyarray, int) not matched by tf2p(int[],anyelement)
|
|
|
|
CREATE AGGREGATE myaggn14a(BASETYPE = int, SFUNC = tf2p, STYPE = anyarray,
|
|
|
|
FINALFUNC = ffnp, INITCOND = '{}');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: cannot determine transition data type
|
Multirange datatypes
Multiranges are basically sorted arrays of non-overlapping ranges with
set-theoretic operations defined over them.
Since v14, each range type automatically gets a corresponding multirange
datatype. There are both manual and automatic mechanisms for naming multirange
types. Once can specify multirange type name using multirange_type_name
attribute in CREATE TYPE. Otherwise, a multirange type name is generated
automatically. If the range type name contains "range" then we change that to
"multirange". Otherwise, we add "_multirange" to the end.
Implementation of multiranges comes with a space-efficient internal
representation format, which evades extra paddings and duplicated storage of
oids. Altogether this format allows fetching a particular range by its index
in O(n).
Statistic gathering and selectivity estimation are implemented for multiranges.
For this purpose, stored multirange is approximated as union range without gaps.
This field will likely need improvements in the future.
Catversion is bumped.
Discussion: https://postgr.es/m/CALNJ-vSUpQ_Y%3DjXvTxt1VYFztaBSsWVXeF1y6gTYQ4bOiWDLgQ%40mail.gmail.com
Discussion: https://postgr.es/m/a0b8026459d1e6167933be2104a6174e7d40d0ab.camel%40j-davis.com#fe7218c83b08068bfffb0c5293eceda0
Author: Paul Jungwirth, revised by me
Reviewed-by: David Fetter, Corey Huinker, Jeff Davis, Pavel Stehule
Reviewed-by: Alvaro Herrera, Tom Lane, Isaac Morland, David G. Johnston
Reviewed-by: Zhihong Yu, Alexander Korotkov
2020-12-20 05:20:33 +01:00
|
|
|
DETAIL: A result of type anyarray requires at least one input of type anyelement, anyarray, anynonarray, anyenum, anyrange, or anymultirange.
|
2003-07-01 21:10:53 +02:00
|
|
|
CREATE AGGREGATE myaggn14b(BASETYPE = int, SFUNC = tf2p, STYPE = anyarray,
|
|
|
|
INITCOND = '{}');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: cannot determine transition data type
|
Multirange datatypes
Multiranges are basically sorted arrays of non-overlapping ranges with
set-theoretic operations defined over them.
Since v14, each range type automatically gets a corresponding multirange
datatype. There are both manual and automatic mechanisms for naming multirange
types. Once can specify multirange type name using multirange_type_name
attribute in CREATE TYPE. Otherwise, a multirange type name is generated
automatically. If the range type name contains "range" then we change that to
"multirange". Otherwise, we add "_multirange" to the end.
Implementation of multiranges comes with a space-efficient internal
representation format, which evades extra paddings and duplicated storage of
oids. Altogether this format allows fetching a particular range by its index
in O(n).
Statistic gathering and selectivity estimation are implemented for multiranges.
For this purpose, stored multirange is approximated as union range without gaps.
This field will likely need improvements in the future.
Catversion is bumped.
Discussion: https://postgr.es/m/CALNJ-vSUpQ_Y%3DjXvTxt1VYFztaBSsWVXeF1y6gTYQ4bOiWDLgQ%40mail.gmail.com
Discussion: https://postgr.es/m/a0b8026459d1e6167933be2104a6174e7d40d0ab.camel%40j-davis.com#fe7218c83b08068bfffb0c5293eceda0
Author: Paul Jungwirth, revised by me
Reviewed-by: David Fetter, Corey Huinker, Jeff Davis, Pavel Stehule
Reviewed-by: Alvaro Herrera, Tom Lane, Isaac Morland, David G. Johnston
Reviewed-by: Zhihong Yu, Alexander Korotkov
2020-12-20 05:20:33 +01:00
|
|
|
DETAIL: A result of type anyarray requires at least one input of type anyelement, anyarray, anynonarray, anyenum, anyrange, or anymultirange.
|
2003-07-01 21:10:53 +02:00
|
|
|
-- P N P N
|
|
|
|
-- should ERROR: tfnp(anyarray, anyelement) not matched by tfnp(int[],int)
|
|
|
|
CREATE AGGREGATE myaggn15a(BASETYPE = anyelement, SFUNC = tfnp,
|
|
|
|
STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}');
|
2003-07-04 04:51:34 +02:00
|
|
|
ERROR: function tfnp(anyarray, anyelement) does not exist
|
2003-07-01 21:10:53 +02:00
|
|
|
CREATE AGGREGATE myaggn15b(BASETYPE = anyelement, SFUNC = tfnp,
|
|
|
|
STYPE = anyarray, INITCOND = '{}');
|
2003-07-04 04:51:34 +02:00
|
|
|
ERROR: function tfnp(anyarray, anyelement) does not exist
|
2003-07-01 21:10:53 +02:00
|
|
|
-- P N P P
|
|
|
|
-- should ERROR: tf2p(anyarray, anyelement) not matched by tf2p(int[],anyelement)
|
|
|
|
CREATE AGGREGATE myaggn16a(BASETYPE = anyelement, SFUNC = tf2p,
|
|
|
|
STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}');
|
2003-07-04 04:51:34 +02:00
|
|
|
ERROR: function tf2p(anyarray, anyelement) does not exist
|
2003-07-01 21:10:53 +02:00
|
|
|
CREATE AGGREGATE myaggn16b(BASETYPE = anyelement, SFUNC = tf2p,
|
|
|
|
STYPE = anyarray, INITCOND = '{}');
|
2003-07-04 04:51:34 +02:00
|
|
|
ERROR: function tf2p(anyarray, anyelement) does not exist
|
2003-07-01 21:10:53 +02:00
|
|
|
-- P P N N
|
|
|
|
-- should ERROR: ffnp(anyarray) not matched by ffnp(int[])
|
|
|
|
CREATE AGGREGATE myaggn17a(BASETYPE = int, SFUNC = tf1p, STYPE = anyarray,
|
|
|
|
FINALFUNC = ffnp, INITCOND = '{}');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: cannot determine transition data type
|
Multirange datatypes
Multiranges are basically sorted arrays of non-overlapping ranges with
set-theoretic operations defined over them.
Since v14, each range type automatically gets a corresponding multirange
datatype. There are both manual and automatic mechanisms for naming multirange
types. Once can specify multirange type name using multirange_type_name
attribute in CREATE TYPE. Otherwise, a multirange type name is generated
automatically. If the range type name contains "range" then we change that to
"multirange". Otherwise, we add "_multirange" to the end.
Implementation of multiranges comes with a space-efficient internal
representation format, which evades extra paddings and duplicated storage of
oids. Altogether this format allows fetching a particular range by its index
in O(n).
Statistic gathering and selectivity estimation are implemented for multiranges.
For this purpose, stored multirange is approximated as union range without gaps.
This field will likely need improvements in the future.
Catversion is bumped.
Discussion: https://postgr.es/m/CALNJ-vSUpQ_Y%3DjXvTxt1VYFztaBSsWVXeF1y6gTYQ4bOiWDLgQ%40mail.gmail.com
Discussion: https://postgr.es/m/a0b8026459d1e6167933be2104a6174e7d40d0ab.camel%40j-davis.com#fe7218c83b08068bfffb0c5293eceda0
Author: Paul Jungwirth, revised by me
Reviewed-by: David Fetter, Corey Huinker, Jeff Davis, Pavel Stehule
Reviewed-by: Alvaro Herrera, Tom Lane, Isaac Morland, David G. Johnston
Reviewed-by: Zhihong Yu, Alexander Korotkov
2020-12-20 05:20:33 +01:00
|
|
|
DETAIL: A result of type anyarray requires at least one input of type anyelement, anyarray, anynonarray, anyenum, anyrange, or anymultirange.
|
2003-07-01 21:10:53 +02:00
|
|
|
-- P P N P
|
|
|
|
-- should ERROR: tfp(anyarray, int) not matched by tfp(anyarray, anyelement)
|
|
|
|
CREATE AGGREGATE myaggn18a(BASETYPE = int, SFUNC = tfp, STYPE = anyarray,
|
|
|
|
FINALFUNC = ffnp, INITCOND = '{}');
|
2003-09-25 08:58:07 +02:00
|
|
|
ERROR: cannot determine transition data type
|
Multirange datatypes
Multiranges are basically sorted arrays of non-overlapping ranges with
set-theoretic operations defined over them.
Since v14, each range type automatically gets a corresponding multirange
datatype. There are both manual and automatic mechanisms for naming multirange
types. Once can specify multirange type name using multirange_type_name
attribute in CREATE TYPE. Otherwise, a multirange type name is generated
automatically. If the range type name contains "range" then we change that to
"multirange". Otherwise, we add "_multirange" to the end.
Implementation of multiranges comes with a space-efficient internal
representation format, which evades extra paddings and duplicated storage of
oids. Altogether this format allows fetching a particular range by its index
in O(n).
Statistic gathering and selectivity estimation are implemented for multiranges.
For this purpose, stored multirange is approximated as union range without gaps.
This field will likely need improvements in the future.
Catversion is bumped.
Discussion: https://postgr.es/m/CALNJ-vSUpQ_Y%3DjXvTxt1VYFztaBSsWVXeF1y6gTYQ4bOiWDLgQ%40mail.gmail.com
Discussion: https://postgr.es/m/a0b8026459d1e6167933be2104a6174e7d40d0ab.camel%40j-davis.com#fe7218c83b08068bfffb0c5293eceda0
Author: Paul Jungwirth, revised by me
Reviewed-by: David Fetter, Corey Huinker, Jeff Davis, Pavel Stehule
Reviewed-by: Alvaro Herrera, Tom Lane, Isaac Morland, David G. Johnston
Reviewed-by: Zhihong Yu, Alexander Korotkov
2020-12-20 05:20:33 +01:00
|
|
|
DETAIL: A result of type anyarray requires at least one input of type anyelement, anyarray, anynonarray, anyenum, anyrange, or anymultirange.
|
2003-07-01 21:10:53 +02:00
|
|
|
-- P P P N
|
|
|
|
-- should ERROR: tf1p(anyarray, anyelement) not matched by tf1p(anyarray, int)
|
|
|
|
CREATE AGGREGATE myaggn19a(BASETYPE = anyelement, SFUNC = tf1p,
|
|
|
|
STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}');
|
2003-07-04 04:51:34 +02:00
|
|
|
ERROR: function tf1p(anyarray, anyelement) does not exist
|
2003-07-01 21:10:53 +02:00
|
|
|
-- P P P P
|
|
|
|
-- should ERROR: ffnp(anyarray) not matched by ffnp(int[])
|
|
|
|
CREATE AGGREGATE myaggn20a(BASETYPE = anyelement, SFUNC = tfp,
|
|
|
|
STYPE = anyarray, FINALFUNC = ffnp, INITCOND = '{}');
|
2003-07-04 04:51:34 +02:00
|
|
|
ERROR: function ffnp(anyarray) does not exist
|
2006-07-27 21:52:07 +02:00
|
|
|
-- multi-arg polymorphic
|
|
|
|
CREATE AGGREGATE mysum2(anyelement,anyelement) (SFUNC = sum3,
|
|
|
|
STYPE = anyelement, INITCOND = '0');
|
2003-07-01 21:10:53 +02:00
|
|
|
-- create test data for polymorphic aggregates
|
|
|
|
create temp table t(f1 int, f2 int[], f3 text);
|
|
|
|
insert into t values(1,array[1],'a');
|
|
|
|
insert into t values(1,array[11],'b');
|
|
|
|
insert into t values(1,array[111],'c');
|
|
|
|
insert into t values(2,array[2],'a');
|
|
|
|
insert into t values(2,array[22],'b');
|
|
|
|
insert into t values(2,array[222],'c');
|
|
|
|
insert into t values(3,array[3],'a');
|
|
|
|
insert into t values(3,array[3],'b');
|
|
|
|
-- test the successfully created polymorphic aggregates
|
2009-02-09 22:18:28 +01:00
|
|
|
select f3, myaggp01a(*) from t group by f3 order by f3;
|
2003-07-01 21:10:53 +02:00
|
|
|
f3 | myaggp01a
|
|
|
|
----+-----------
|
2009-02-09 22:18:28 +01:00
|
|
|
a | {}
|
2005-03-24 20:14:49 +01:00
|
|
|
b | {}
|
2003-07-01 21:10:53 +02:00
|
|
|
c | {}
|
|
|
|
(3 rows)
|
|
|
|
|
2009-02-09 22:18:28 +01:00
|
|
|
select f3, myaggp03a(*) from t group by f3 order by f3;
|
2003-07-01 21:10:53 +02:00
|
|
|
f3 | myaggp03a
|
|
|
|
----+-----------
|
2009-02-09 22:18:28 +01:00
|
|
|
a | {}
|
2005-03-24 20:14:49 +01:00
|
|
|
b | {}
|
2003-07-01 21:10:53 +02:00
|
|
|
c | {}
|
|
|
|
(3 rows)
|
|
|
|
|
2009-02-09 22:18:28 +01:00
|
|
|
select f3, myaggp03b(*) from t group by f3 order by f3;
|
2003-07-01 21:10:53 +02:00
|
|
|
f3 | myaggp03b
|
|
|
|
----+-----------
|
2009-02-09 22:18:28 +01:00
|
|
|
a | {}
|
2005-03-24 20:14:49 +01:00
|
|
|
b | {}
|
2003-07-01 21:10:53 +02:00
|
|
|
c | {}
|
|
|
|
(3 rows)
|
|
|
|
|
2009-02-09 22:18:28 +01:00
|
|
|
select f3, myaggp05a(f1) from t group by f3 order by f3;
|
2003-07-01 21:10:53 +02:00
|
|
|
f3 | myaggp05a
|
|
|
|
----+-----------
|
2009-02-09 22:18:28 +01:00
|
|
|
a | {1,2,3}
|
2005-03-24 20:14:49 +01:00
|
|
|
b | {1,2,3}
|
2003-07-01 21:10:53 +02:00
|
|
|
c | {1,2}
|
|
|
|
(3 rows)
|
|
|
|
|
2009-02-09 22:18:28 +01:00
|
|
|
select f3, myaggp06a(f1) from t group by f3 order by f3;
|
2003-07-01 21:10:53 +02:00
|
|
|
f3 | myaggp06a
|
|
|
|
----+-----------
|
2009-02-09 22:18:28 +01:00
|
|
|
a | {}
|
2005-03-24 20:14:49 +01:00
|
|
|
b | {}
|
2003-07-01 21:10:53 +02:00
|
|
|
c | {}
|
|
|
|
(3 rows)
|
|
|
|
|
2009-02-09 22:18:28 +01:00
|
|
|
select f3, myaggp08a(f1) from t group by f3 order by f3;
|
2003-07-01 21:10:53 +02:00
|
|
|
f3 | myaggp08a
|
|
|
|
----+-----------
|
2009-02-09 22:18:28 +01:00
|
|
|
a | {}
|
2005-03-24 20:14:49 +01:00
|
|
|
b | {}
|
2003-07-01 21:10:53 +02:00
|
|
|
c | {}
|
|
|
|
(3 rows)
|
|
|
|
|
2009-02-09 22:18:28 +01:00
|
|
|
select f3, myaggp09a(f1) from t group by f3 order by f3;
|
2003-07-01 21:10:53 +02:00
|
|
|
f3 | myaggp09a
|
|
|
|
----+-----------
|
2009-02-09 22:18:28 +01:00
|
|
|
a | {}
|
2005-03-24 20:14:49 +01:00
|
|
|
b | {}
|
2003-07-01 21:10:53 +02:00
|
|
|
c | {}
|
|
|
|
(3 rows)
|
|
|
|
|
2009-02-09 22:18:28 +01:00
|
|
|
select f3, myaggp09b(f1) from t group by f3 order by f3;
|
2003-07-01 21:10:53 +02:00
|
|
|
f3 | myaggp09b
|
|
|
|
----+-----------
|
2009-02-09 22:18:28 +01:00
|
|
|
a | {}
|
2005-03-24 20:14:49 +01:00
|
|
|
b | {}
|
2003-07-01 21:10:53 +02:00
|
|
|
c | {}
|
|
|
|
(3 rows)
|
|
|
|
|
2009-02-09 22:18:28 +01:00
|
|
|
select f3, myaggp10a(f1) from t group by f3 order by f3;
|
2003-07-01 21:10:53 +02:00
|
|
|
f3 | myaggp10a
|
|
|
|
----+-----------
|
2009-02-09 22:18:28 +01:00
|
|
|
a | {1,2,3}
|
2005-03-24 20:14:49 +01:00
|
|
|
b | {1,2,3}
|
2003-07-01 21:10:53 +02:00
|
|
|
c | {1,2}
|
|
|
|
(3 rows)
|
|
|
|
|
2009-02-09 22:18:28 +01:00
|
|
|
select f3, myaggp10b(f1) from t group by f3 order by f3;
|
2003-07-01 21:10:53 +02:00
|
|
|
f3 | myaggp10b
|
|
|
|
----+-----------
|
2009-02-09 22:18:28 +01:00
|
|
|
a | {1,2,3}
|
2005-03-24 20:14:49 +01:00
|
|
|
b | {1,2,3}
|
2003-07-01 21:10:53 +02:00
|
|
|
c | {1,2}
|
|
|
|
(3 rows)
|
|
|
|
|
2009-02-09 22:18:28 +01:00
|
|
|
select f3, myaggp20a(f1) from t group by f3 order by f3;
|
2003-07-01 21:10:53 +02:00
|
|
|
f3 | myaggp20a
|
|
|
|
----+-----------
|
2009-02-09 22:18:28 +01:00
|
|
|
a | {1,2,3}
|
2005-03-24 20:14:49 +01:00
|
|
|
b | {1,2,3}
|
2003-07-01 21:10:53 +02:00
|
|
|
c | {1,2}
|
|
|
|
(3 rows)
|
|
|
|
|
2009-02-09 22:18:28 +01:00
|
|
|
select f3, myaggp20b(f1) from t group by f3 order by f3;
|
2003-07-01 21:10:53 +02:00
|
|
|
f3 | myaggp20b
|
|
|
|
----+-----------
|
2009-02-09 22:18:28 +01:00
|
|
|
a | {1,2,3}
|
2005-03-24 20:14:49 +01:00
|
|
|
b | {1,2,3}
|
2003-07-01 21:10:53 +02:00
|
|
|
c | {1,2}
|
|
|
|
(3 rows)
|
|
|
|
|
2009-02-09 22:18:28 +01:00
|
|
|
select f3, myaggn01a(*) from t group by f3 order by f3;
|
2003-07-01 21:10:53 +02:00
|
|
|
f3 | myaggn01a
|
|
|
|
----+-----------
|
2009-02-09 22:18:28 +01:00
|
|
|
a | {}
|
2005-03-24 20:14:49 +01:00
|
|
|
b | {}
|
2003-07-01 21:10:53 +02:00
|
|
|
c | {}
|
|
|
|
(3 rows)
|
|
|
|
|
2009-02-09 22:18:28 +01:00
|
|
|
select f3, myaggn01b(*) from t group by f3 order by f3;
|
2003-07-01 21:10:53 +02:00
|
|
|
f3 | myaggn01b
|
|
|
|
----+-----------
|
2009-02-09 22:18:28 +01:00
|
|
|
a | {}
|
2005-03-24 20:14:49 +01:00
|
|
|
b | {}
|
2003-07-01 21:10:53 +02:00
|
|
|
c | {}
|
|
|
|
(3 rows)
|
|
|
|
|
2009-02-09 22:18:28 +01:00
|
|
|
select f3, myaggn03a(*) from t group by f3 order by f3;
|
2003-07-01 21:10:53 +02:00
|
|
|
f3 | myaggn03a
|
|
|
|
----+-----------
|
2009-02-09 22:18:28 +01:00
|
|
|
a | {}
|
2005-03-24 20:14:49 +01:00
|
|
|
b | {}
|
2003-07-01 21:10:53 +02:00
|
|
|
c | {}
|
|
|
|
(3 rows)
|
|
|
|
|
2009-02-09 22:18:28 +01:00
|
|
|
select f3, myaggn05a(f1) from t group by f3 order by f3;
|
2003-07-01 21:10:53 +02:00
|
|
|
f3 | myaggn05a
|
|
|
|
----+-----------
|
2009-02-09 22:18:28 +01:00
|
|
|
a | {1,2,3}
|
2005-03-24 20:14:49 +01:00
|
|
|
b | {1,2,3}
|
2003-07-01 21:10:53 +02:00
|
|
|
c | {1,2}
|
|
|
|
(3 rows)
|
|
|
|
|
2009-02-09 22:18:28 +01:00
|
|
|
select f3, myaggn05b(f1) from t group by f3 order by f3;
|
2003-07-01 21:10:53 +02:00
|
|
|
f3 | myaggn05b
|
|
|
|
----+-----------
|
2009-02-09 22:18:28 +01:00
|
|
|
a | {1,2,3}
|
2005-03-24 20:14:49 +01:00
|
|
|
b | {1,2,3}
|
2003-07-01 21:10:53 +02:00
|
|
|
c | {1,2}
|
|
|
|
(3 rows)
|
|
|
|
|
2009-02-09 22:18:28 +01:00
|
|
|
select f3, myaggn06a(f1) from t group by f3 order by f3;
|
2003-07-01 21:10:53 +02:00
|
|
|
f3 | myaggn06a
|
|
|
|
----+-----------
|
2009-02-09 22:18:28 +01:00
|
|
|
a | {}
|
2005-03-24 20:14:49 +01:00
|
|
|
b | {}
|
2003-07-01 21:10:53 +02:00
|
|
|
c | {}
|
|
|
|
(3 rows)
|
|
|
|
|
2009-02-09 22:18:28 +01:00
|
|
|
select f3, myaggn06b(f1) from t group by f3 order by f3;
|
2003-07-01 21:10:53 +02:00
|
|
|
f3 | myaggn06b
|
|
|
|
----+-----------
|
2009-02-09 22:18:28 +01:00
|
|
|
a | {}
|
2005-03-24 20:14:49 +01:00
|
|
|
b | {}
|
2003-07-01 21:10:53 +02:00
|
|
|
c | {}
|
|
|
|
(3 rows)
|
|
|
|
|
2009-02-09 22:18:28 +01:00
|
|
|
select f3, myaggn08a(f1) from t group by f3 order by f3;
|
2003-07-01 21:10:53 +02:00
|
|
|
f3 | myaggn08a
|
|
|
|
----+-----------
|
2009-02-09 22:18:28 +01:00
|
|
|
a | {}
|
2005-03-24 20:14:49 +01:00
|
|
|
b | {}
|
2003-07-01 21:10:53 +02:00
|
|
|
c | {}
|
|
|
|
(3 rows)
|
|
|
|
|
2009-02-09 22:18:28 +01:00
|
|
|
select f3, myaggn08b(f1) from t group by f3 order by f3;
|
2003-07-01 21:10:53 +02:00
|
|
|
f3 | myaggn08b
|
|
|
|
----+-----------
|
2009-02-09 22:18:28 +01:00
|
|
|
a | {}
|
2005-03-24 20:14:49 +01:00
|
|
|
b | {}
|
2003-07-01 21:10:53 +02:00
|
|
|
c | {}
|
|
|
|
(3 rows)
|
|
|
|
|
2009-02-09 22:18:28 +01:00
|
|
|
select f3, myaggn09a(f1) from t group by f3 order by f3;
|
2003-07-01 21:10:53 +02:00
|
|
|
f3 | myaggn09a
|
|
|
|
----+-----------
|
2009-02-09 22:18:28 +01:00
|
|
|
a | {}
|
2005-03-24 20:14:49 +01:00
|
|
|
b | {}
|
2003-07-01 21:10:53 +02:00
|
|
|
c | {}
|
|
|
|
(3 rows)
|
|
|
|
|
2009-02-09 22:18:28 +01:00
|
|
|
select f3, myaggn10a(f1) from t group by f3 order by f3;
|
2003-07-01 21:10:53 +02:00
|
|
|
f3 | myaggn10a
|
|
|
|
----+-----------
|
2009-02-09 22:18:28 +01:00
|
|
|
a | {1,2,3}
|
2005-03-24 20:14:49 +01:00
|
|
|
b | {1,2,3}
|
2003-07-01 21:10:53 +02:00
|
|
|
c | {1,2}
|
|
|
|
(3 rows)
|
|
|
|
|
2006-07-27 21:52:07 +02:00
|
|
|
select mysum2(f1, f1 + 1) from t;
|
|
|
|
mysum2
|
|
|
|
--------
|
|
|
|
38
|
|
|
|
(1 row)
|
|
|
|
|
2007-05-01 20:53:52 +02:00
|
|
|
-- test inlining of polymorphic SQL functions
|
|
|
|
create function bleat(int) returns int as $$
|
|
|
|
begin
|
|
|
|
raise notice 'bleat %', $1;
|
|
|
|
return $1;
|
|
|
|
end$$ language plpgsql;
|
|
|
|
create function sql_if(bool, anyelement, anyelement) returns anyelement as $$
|
|
|
|
select case when $1 then $2 else $3 end $$ language sql;
|
|
|
|
-- Note this would fail with integer overflow, never mind wrong bleat() output,
|
|
|
|
-- if the CASE expression were not successfully inlined
|
|
|
|
select f1, sql_if(f1 > 0, bleat(f1), bleat(f1 + 1)) from int4_tbl;
|
|
|
|
NOTICE: bleat 1
|
|
|
|
NOTICE: bleat 123456
|
|
|
|
NOTICE: bleat -123455
|
|
|
|
NOTICE: bleat 2147483647
|
|
|
|
NOTICE: bleat -2147483646
|
|
|
|
f1 | sql_if
|
|
|
|
-------------+-------------
|
|
|
|
0 | 1
|
|
|
|
123456 | 123456
|
|
|
|
-123456 | -123455
|
|
|
|
2147483647 | 2147483647
|
|
|
|
-2147483647 | -2147483646
|
|
|
|
(5 rows)
|
|
|
|
|
|
|
|
select q2, sql_if(q2 > 0, q2, q2 + 1) from int8_tbl;
|
|
|
|
q2 | sql_if
|
|
|
|
-------------------+-------------------
|
|
|
|
456 | 456
|
|
|
|
4567890123456789 | 4567890123456789
|
|
|
|
123 | 123
|
|
|
|
4567890123456789 | 4567890123456789
|
|
|
|
-4567890123456789 | -4567890123456788
|
|
|
|
(5 rows)
|
|
|
|
|
2011-12-01 18:44:16 +01:00
|
|
|
-- another sort of polymorphic aggregate
|
2020-11-11 00:32:36 +01:00
|
|
|
CREATE AGGREGATE array_larger_accum (anyarray)
|
2011-12-01 18:44:16 +01:00
|
|
|
(
|
2020-11-11 00:32:36 +01:00
|
|
|
sfunc = array_larger,
|
|
|
|
stype = anyarray,
|
2011-12-01 18:44:16 +01:00
|
|
|
initcond = '{}'
|
|
|
|
);
|
2020-11-11 00:32:36 +01:00
|
|
|
SELECT array_larger_accum(i)
|
2011-12-01 18:44:16 +01:00
|
|
|
FROM (VALUES (ARRAY[1,2]), (ARRAY[3,4])) as t(i);
|
2020-11-11 00:32:36 +01:00
|
|
|
array_larger_accum
|
|
|
|
--------------------
|
|
|
|
{3,4}
|
2011-12-01 18:44:16 +01:00
|
|
|
(1 row)
|
|
|
|
|
2020-11-11 00:32:36 +01:00
|
|
|
SELECT array_larger_accum(i)
|
2011-12-01 18:44:16 +01:00
|
|
|
FROM (VALUES (ARRAY[row(1,2),row(3,4)]), (ARRAY[row(5,6),row(7,8)])) as t(i);
|
2020-11-11 00:32:36 +01:00
|
|
|
array_larger_accum
|
|
|
|
--------------------
|
|
|
|
{"(5,6)","(7,8)"}
|
2011-12-01 18:44:16 +01:00
|
|
|
(1 row)
|
|
|
|
|
2008-01-11 19:39:41 +01:00
|
|
|
-- 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[]
|
|
|
|
);
|
2016-10-09 18:49:37 +02:00
|
|
|
-- check proper resolution of data types for polymorphic transfn/finalfn
|
2020-11-11 00:32:36 +01:00
|
|
|
create function first_el_transfn(anyarray, anyelement) returns anyarray as
|
|
|
|
'select $1 || $2' language sql immutable;
|
|
|
|
create function first_el(anyarray) returns anyelement as
|
2016-10-09 18:49:37 +02:00
|
|
|
'select $1[1]' language sql strict immutable;
|
|
|
|
create aggregate first_el_agg_f8(float8) (
|
|
|
|
SFUNC = array_append,
|
|
|
|
STYPE = float8[],
|
|
|
|
FINALFUNC = first_el
|
|
|
|
);
|
2020-11-11 00:32:36 +01:00
|
|
|
create aggregate first_el_agg_any(anyelement) (
|
|
|
|
SFUNC = first_el_transfn,
|
|
|
|
STYPE = anyarray,
|
2016-10-09 18:49:37 +02:00
|
|
|
FINALFUNC = first_el
|
|
|
|
);
|
|
|
|
select first_el_agg_f8(x::float8) from generate_series(1,10) x;
|
|
|
|
first_el_agg_f8
|
|
|
|
-----------------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select first_el_agg_any(x) from generate_series(1,10) x;
|
|
|
|
first_el_agg_any
|
|
|
|
------------------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select first_el_agg_f8(x::float8) over(order by x) from generate_series(1,10) x;
|
|
|
|
first_el_agg_f8
|
|
|
|
-----------------
|
|
|
|
1
|
|
|
|
1
|
|
|
|
1
|
|
|
|
1
|
|
|
|
1
|
|
|
|
1
|
|
|
|
1
|
|
|
|
1
|
|
|
|
1
|
|
|
|
1
|
|
|
|
(10 rows)
|
|
|
|
|
|
|
|
select first_el_agg_any(x) over(order by x) from generate_series(1,10) x;
|
|
|
|
first_el_agg_any
|
|
|
|
------------------
|
|
|
|
1
|
|
|
|
1
|
|
|
|
1
|
|
|
|
1
|
|
|
|
1
|
|
|
|
1
|
|
|
|
1
|
|
|
|
1
|
|
|
|
1
|
|
|
|
1
|
|
|
|
(10 rows)
|
|
|
|
|
2008-12-14 20:45:52 +01:00
|
|
|
-- check that we can apply functions taking ANYARRAY to pg_stats
|
|
|
|
select distinct array_ndims(histogram_bounds) from pg_stats
|
|
|
|
where histogram_bounds is not null;
|
|
|
|
array_ndims
|
|
|
|
-------------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- such functions must protect themselves if varying element type isn't OK
|
2011-03-14 17:52:03 +01:00
|
|
|
-- (WHERE clause here is to avoid possibly getting a collation error instead)
|
|
|
|
select max(histogram_bounds) from pg_stats where tablename = 'pg_am';
|
2008-12-14 20:45:52 +01:00
|
|
|
ERROR: cannot compare arrays of different element types
|
2020-04-05 00:03:30 +02:00
|
|
|
-- another corner case is the input functions for polymorphic pseudotypes
|
|
|
|
select array_in('{1,2,3}','int4'::regtype,-1); -- this has historically worked
|
|
|
|
array_in
|
|
|
|
----------
|
|
|
|
{1,2,3}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select * from array_in('{1,2,3}','int4'::regtype,-1); -- this not
|
|
|
|
ERROR: function "array_in" in FROM has unsupported return type anyarray
|
|
|
|
LINE 1: select * from array_in('{1,2,3}','int4'::regtype,-1);
|
|
|
|
^
|
|
|
|
select anyrange_in('[10,20)','int4range'::regtype,-1);
|
|
|
|
ERROR: cannot accept a value of type anyrange
|
2008-07-16 03:30:23 +02:00
|
|
|
-- test variadic polymorphic functions
|
|
|
|
create function myleast(variadic anyarray) returns anyelement as $$
|
|
|
|
select min($1[i]) from generate_subscripts($1,1) g(i)
|
|
|
|
$$ language sql immutable strict;
|
|
|
|
select myleast(10, 1, 20, 33);
|
|
|
|
myleast
|
|
|
|
---------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select myleast(1.1, 0.22, 0.55);
|
|
|
|
myleast
|
|
|
|
---------
|
|
|
|
0.22
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select myleast('z'::text);
|
|
|
|
myleast
|
|
|
|
---------
|
|
|
|
z
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select myleast(); -- fail
|
|
|
|
ERROR: function myleast() does not exist
|
|
|
|
LINE 1: select myleast();
|
|
|
|
^
|
|
|
|
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
|
|
|
|
-- test with variadic call parameter
|
|
|
|
select myleast(variadic array[1,2,3,4,-1]);
|
|
|
|
myleast
|
|
|
|
---------
|
|
|
|
-1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select myleast(variadic array[1.1, -5.5]);
|
|
|
|
myleast
|
|
|
|
---------
|
|
|
|
-5.5
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
--test with empty variadic call parameter
|
|
|
|
select myleast(variadic array[]::int[]);
|
|
|
|
myleast
|
|
|
|
---------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- an example with some ordinary arguments too
|
|
|
|
create function concat(text, variadic anyarray) returns text as $$
|
|
|
|
select array_to_string($2, $1);
|
|
|
|
$$ language sql immutable strict;
|
|
|
|
select concat('%', 1, 2, 3, 4, 5);
|
|
|
|
concat
|
|
|
|
-----------
|
|
|
|
1%2%3%4%5
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select concat('|', 'a'::text, 'b', 'c');
|
|
|
|
concat
|
|
|
|
--------
|
|
|
|
a|b|c
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select concat('|', variadic array[1,2,33]);
|
|
|
|
concat
|
|
|
|
--------
|
|
|
|
1|2|33
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select concat('|', variadic array[]::int[]);
|
|
|
|
concat
|
|
|
|
--------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
drop function concat(text, anyarray);
|
|
|
|
-- mix variadic with anyelement
|
|
|
|
create function formarray(anyelement, variadic anyarray) returns anyarray as $$
|
|
|
|
select array_prepend($1, $2);
|
|
|
|
$$ language sql immutable strict;
|
|
|
|
select formarray(1,2,3,4,5);
|
|
|
|
formarray
|
|
|
|
-------------
|
|
|
|
{1,2,3,4,5}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select formarray(1.1, variadic array[1.2,55.5]);
|
|
|
|
formarray
|
|
|
|
----------------
|
|
|
|
{1.1,1.2,55.5}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select formarray(1.1, array[1.2,55.5]); -- fail without variadic
|
|
|
|
ERROR: function formarray(numeric, numeric[]) does not exist
|
|
|
|
LINE 1: select formarray(1.1, array[1.2,55.5]);
|
|
|
|
^
|
|
|
|
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
|
|
|
|
select formarray(1, 'x'::text); -- fail, type mismatch
|
|
|
|
ERROR: function formarray(integer, text) does not exist
|
|
|
|
LINE 1: select formarray(1, 'x'::text);
|
|
|
|
^
|
|
|
|
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
|
|
|
|
select formarray(1, variadic array['x'::text]); -- fail, type mismatch
|
|
|
|
ERROR: function formarray(integer, text[]) does not exist
|
|
|
|
LINE 1: select formarray(1, variadic array['x'::text]);
|
|
|
|
^
|
|
|
|
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
|
|
|
|
drop function formarray(anyelement, variadic anyarray);
|
2008-11-03 18:51:13 +01:00
|
|
|
-- test pg_typeof() function
|
|
|
|
select pg_typeof(null); -- unknown
|
|
|
|
pg_typeof
|
|
|
|
-----------
|
|
|
|
unknown
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select pg_typeof(0); -- integer
|
|
|
|
pg_typeof
|
|
|
|
-----------
|
|
|
|
integer
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select pg_typeof(0.0); -- numeric
|
|
|
|
pg_typeof
|
|
|
|
-----------
|
|
|
|
numeric
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select pg_typeof(1+1 = 2); -- boolean
|
|
|
|
pg_typeof
|
|
|
|
-----------
|
|
|
|
boolean
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select pg_typeof('x'); -- unknown
|
|
|
|
pg_typeof
|
|
|
|
-----------
|
|
|
|
unknown
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select pg_typeof('' || ''); -- text
|
|
|
|
pg_typeof
|
|
|
|
-----------
|
|
|
|
text
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select pg_typeof(pg_typeof(0)); -- regtype
|
|
|
|
pg_typeof
|
|
|
|
-----------
|
|
|
|
regtype
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select pg_typeof(array[1.2,55.5]); -- numeric[]
|
|
|
|
pg_typeof
|
|
|
|
-----------
|
|
|
|
numeric[]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select pg_typeof(myleast(10, 1, 20, 33)); -- polymorphic input
|
|
|
|
pg_typeof
|
|
|
|
-----------
|
|
|
|
integer
|
|
|
|
(1 row)
|
|
|
|
|
2008-12-18 19:20:35 +01:00
|
|
|
-- test functions with default parameters
|
2008-12-04 18:51:28 +01:00
|
|
|
-- test basic functionality
|
|
|
|
create function dfunc(a int = 1, int = 2) returns int as $$
|
|
|
|
select $1 + $2;
|
|
|
|
$$ language sql;
|
|
|
|
select dfunc();
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
3
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc(10);
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
12
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc(10, 20);
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
30
|
|
|
|
(1 row)
|
|
|
|
|
2008-12-18 19:20:35 +01:00
|
|
|
select dfunc(10, 20, 30); -- fail
|
|
|
|
ERROR: function dfunc(integer, integer, integer) does not exist
|
|
|
|
LINE 1: select dfunc(10, 20, 30);
|
|
|
|
^
|
|
|
|
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
|
2008-12-04 18:51:28 +01:00
|
|
|
drop function dfunc(); -- fail
|
|
|
|
ERROR: function dfunc() does not exist
|
|
|
|
drop function dfunc(int); -- fail
|
|
|
|
ERROR: function dfunc(integer) does not exist
|
|
|
|
drop function dfunc(int, int); -- ok
|
2008-12-18 19:20:35 +01:00
|
|
|
-- fail: defaults must be at end of argument list
|
2008-12-04 18:51:28 +01:00
|
|
|
create function dfunc(a int = 1, b int) returns int as $$
|
|
|
|
select $1 + $2;
|
|
|
|
$$ language sql;
|
2008-12-18 19:20:35 +01:00
|
|
|
ERROR: input parameters after one with a default value must also have defaults
|
|
|
|
-- however, this should work:
|
|
|
|
create function dfunc(a int = 1, out sum int, b int = 2) as $$
|
|
|
|
select $1 + $2;
|
|
|
|
$$ language sql;
|
|
|
|
select dfunc();
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
3
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- verify it lists properly
|
|
|
|
\df dfunc
|
2017-11-30 14:46:13 +01:00
|
|
|
List of functions
|
|
|
|
Schema | Name | Result data type | Argument data types | Type
|
|
|
|
--------+-------+------------------+-----------------------------------------------------------+------
|
|
|
|
public | dfunc | integer | a integer DEFAULT 1, OUT sum integer, b integer DEFAULT 2 | func
|
2008-12-18 19:20:35 +01:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
drop function dfunc(int, int);
|
|
|
|
-- check implicit coercion
|
2008-12-04 18:51:28 +01:00
|
|
|
create function dfunc(a int DEFAULT 1.0, int DEFAULT '-1') returns int as $$
|
|
|
|
select $1 + $2;
|
|
|
|
$$ language sql;
|
|
|
|
select dfunc();
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
0
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
create function dfunc(a text DEFAULT 'Hello', b text DEFAULT 'World') returns text as $$
|
|
|
|
select $1 || ', ' || $2;
|
|
|
|
$$ language sql;
|
2008-12-18 19:20:35 +01:00
|
|
|
select dfunc(); -- fail: which dfunc should be called? int or text
|
|
|
|
ERROR: function dfunc() is not unique
|
|
|
|
LINE 1: select dfunc();
|
|
|
|
^
|
|
|
|
HINT: Could not choose a best candidate function. You might need to add explicit type casts.
|
2008-12-04 18:51:28 +01:00
|
|
|
select dfunc('Hi'); -- ok
|
|
|
|
dfunc
|
|
|
|
-----------
|
|
|
|
Hi, World
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc('Hi', 'City'); -- ok
|
|
|
|
dfunc
|
|
|
|
----------
|
|
|
|
Hi, City
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc(0); -- ok
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
-1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc(10, 20); -- ok
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
30
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
drop function dfunc(int, int);
|
|
|
|
drop function dfunc(text, text);
|
|
|
|
create function dfunc(int = 1, int = 2) returns int as $$
|
2008-12-18 19:20:35 +01:00
|
|
|
select 2;
|
2008-12-04 18:51:28 +01:00
|
|
|
$$ language sql;
|
|
|
|
create function dfunc(int = 1, int = 2, int = 3, int = 4) returns int as $$
|
|
|
|
select 4;
|
|
|
|
$$ language sql;
|
|
|
|
-- Now, dfunc(nargs = 2) and dfunc(nargs = 4) are ambiguous when called
|
2008-12-18 19:20:35 +01:00
|
|
|
-- with 0 to 2 arguments.
|
2008-12-04 18:51:28 +01:00
|
|
|
select dfunc(); -- fail
|
2008-12-18 19:20:35 +01:00
|
|
|
ERROR: function dfunc() is not unique
|
|
|
|
LINE 1: select dfunc();
|
|
|
|
^
|
|
|
|
HINT: Could not choose a best candidate function. You might need to add explicit type casts.
|
2008-12-04 18:51:28 +01:00
|
|
|
select dfunc(1); -- fail
|
2008-12-18 19:20:35 +01:00
|
|
|
ERROR: function dfunc(integer) is not unique
|
|
|
|
LINE 1: select dfunc(1);
|
|
|
|
^
|
|
|
|
HINT: Could not choose a best candidate function. You might need to add explicit type casts.
|
|
|
|
select dfunc(1, 2); -- fail
|
|
|
|
ERROR: function dfunc(integer, integer) is not unique
|
|
|
|
LINE 1: select dfunc(1, 2);
|
|
|
|
^
|
|
|
|
HINT: Could not choose a best candidate function. You might need to add explicit type casts.
|
2008-12-04 18:51:28 +01:00
|
|
|
select dfunc(1, 2, 3); -- ok
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
4
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc(1, 2, 3, 4); -- ok
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
4
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
drop function dfunc(int, int);
|
|
|
|
drop function dfunc(int, int, int, int);
|
|
|
|
-- default values are not allowed for output parameters
|
|
|
|
create function dfunc(out int = 20) returns int as $$
|
2008-12-18 19:20:35 +01:00
|
|
|
select 1;
|
2008-12-04 18:51:28 +01:00
|
|
|
$$ language sql;
|
2008-12-18 19:20:35 +01:00
|
|
|
ERROR: only input parameters can have default values
|
2008-12-04 18:51:28 +01:00
|
|
|
-- polymorphic parameter test
|
|
|
|
create function dfunc(anyelement = 'World'::text) returns text as $$
|
|
|
|
select 'Hello, ' || $1::text;
|
|
|
|
$$ language sql;
|
|
|
|
select dfunc();
|
|
|
|
dfunc
|
|
|
|
--------------
|
|
|
|
Hello, World
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc(0);
|
|
|
|
dfunc
|
|
|
|
----------
|
|
|
|
Hello, 0
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc(to_date('20081215','YYYYMMDD'));
|
|
|
|
dfunc
|
|
|
|
-------------------
|
|
|
|
Hello, 12-15-2008
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc('City'::text);
|
|
|
|
dfunc
|
|
|
|
-------------
|
|
|
|
Hello, City
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
drop function dfunc(anyelement);
|
2008-12-18 19:20:35 +01:00
|
|
|
-- check defaults for variadics
|
|
|
|
create function dfunc(a variadic int[]) returns int as
|
|
|
|
$$ select array_upper($1, 1) $$ language sql;
|
|
|
|
select dfunc(); -- fail
|
|
|
|
ERROR: function dfunc() does not exist
|
|
|
|
LINE 1: select dfunc();
|
|
|
|
^
|
|
|
|
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
|
|
|
|
select dfunc(10);
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
1
|
2008-12-04 18:51:28 +01:00
|
|
|
(1 row)
|
|
|
|
|
2008-12-18 19:20:35 +01:00
|
|
|
select dfunc(10,20);
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
2
|
2008-12-04 18:51:28 +01:00
|
|
|
(1 row)
|
|
|
|
|
2008-12-18 19:20:35 +01:00
|
|
|
create or replace function dfunc(a variadic int[] default array[]::int[]) returns int as
|
|
|
|
$$ select array_upper($1, 1) $$ language sql;
|
|
|
|
select dfunc(); -- now ok
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
|
2008-12-04 18:51:28 +01:00
|
|
|
(1 row)
|
|
|
|
|
2008-12-18 19:20:35 +01:00
|
|
|
select dfunc(10);
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc(10,20);
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
2
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- can't remove the default once it exists
|
|
|
|
create or replace function dfunc(a variadic int[]) returns int as
|
|
|
|
$$ select array_upper($1, 1) $$ language sql;
|
|
|
|
ERROR: cannot remove parameter defaults from existing function
|
2012-06-26 19:33:23 +02:00
|
|
|
HINT: Use DROP FUNCTION dfunc(integer[]) first.
|
2008-12-18 19:20:35 +01:00
|
|
|
\df dfunc
|
2017-11-30 14:46:13 +01:00
|
|
|
List of functions
|
|
|
|
Schema | Name | Result data type | Argument data types | Type
|
|
|
|
--------+-------+------------------+-------------------------------------------------+------
|
|
|
|
public | dfunc | integer | VARIADIC a integer[] DEFAULT ARRAY[]::integer[] | func
|
2008-12-18 19:20:35 +01:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
drop function dfunc(a variadic int[]);
|
|
|
|
-- Ambiguity should be reported only if there's not a better match available
|
2008-12-04 18:51:28 +01:00
|
|
|
create function dfunc(int = 1, int = 2, int = 3) returns int as $$
|
|
|
|
select 3;
|
|
|
|
$$ language sql;
|
|
|
|
create function dfunc(int = 1, int = 2) returns int as $$
|
|
|
|
select 2;
|
|
|
|
$$ language sql;
|
|
|
|
create function dfunc(text) returns text as $$
|
|
|
|
select $1;
|
|
|
|
$$ language sql;
|
2008-12-18 19:20:35 +01:00
|
|
|
-- dfunc(narg=2) and dfunc(narg=3) are ambiguous
|
|
|
|
select dfunc(1); -- fail
|
|
|
|
ERROR: function dfunc(integer) is not unique
|
|
|
|
LINE 1: select dfunc(1);
|
|
|
|
^
|
|
|
|
HINT: Could not choose a best candidate function. You might need to add explicit type casts.
|
|
|
|
-- but this works since the ambiguous functions aren't preferred anyway
|
2008-12-04 18:51:28 +01:00
|
|
|
select dfunc('Hi');
|
2008-12-18 19:20:35 +01:00
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
Hi
|
|
|
|
(1 row)
|
|
|
|
|
2008-12-04 18:51:28 +01:00
|
|
|
drop function dfunc(int, int, int);
|
|
|
|
drop function dfunc(int, int);
|
|
|
|
drop function dfunc(text);
|
2009-10-08 04:39:25 +02:00
|
|
|
--
|
|
|
|
-- Tests for named- and mixed-notation function calling
|
|
|
|
--
|
|
|
|
create function dfunc(a int, b int, c int = 0, d int = 0)
|
|
|
|
returns table (a int, b int, c int, d int) as $$
|
|
|
|
select $1, $2, $3, $4;
|
|
|
|
$$ language sql;
|
|
|
|
select (dfunc(10,20,30)).*;
|
|
|
|
a | b | c | d
|
|
|
|
----+----+----+---
|
|
|
|
10 | 20 | 30 | 0
|
|
|
|
(1 row)
|
|
|
|
|
2010-05-30 20:10:41 +02:00
|
|
|
select (dfunc(a := 10, b := 20, c := 30)).*;
|
2009-10-08 04:39:25 +02:00
|
|
|
a | b | c | d
|
|
|
|
----+----+----+---
|
|
|
|
10 | 20 | 30 | 0
|
|
|
|
(1 row)
|
|
|
|
|
2010-05-30 20:10:41 +02:00
|
|
|
select * from dfunc(a := 10, b := 20);
|
2009-10-08 04:39:25 +02:00
|
|
|
a | b | c | d
|
|
|
|
----+----+---+---
|
|
|
|
10 | 20 | 0 | 0
|
|
|
|
(1 row)
|
|
|
|
|
2010-05-30 20:10:41 +02:00
|
|
|
select * from dfunc(b := 10, a := 20);
|
2009-10-08 04:39:25 +02:00
|
|
|
a | b | c | d
|
|
|
|
----+----+---+---
|
|
|
|
20 | 10 | 0 | 0
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select * from dfunc(0); -- fail
|
|
|
|
ERROR: function dfunc(integer) does not exist
|
|
|
|
LINE 1: select * from dfunc(0);
|
|
|
|
^
|
|
|
|
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
|
|
|
|
select * from dfunc(1,2);
|
|
|
|
a | b | c | d
|
|
|
|
---+---+---+---
|
|
|
|
1 | 2 | 0 | 0
|
|
|
|
(1 row)
|
|
|
|
|
2010-05-30 20:10:41 +02:00
|
|
|
select * from dfunc(1,2,c := 3);
|
2009-10-08 04:39:25 +02:00
|
|
|
a | b | c | d
|
|
|
|
---+---+---+---
|
|
|
|
1 | 2 | 3 | 0
|
|
|
|
(1 row)
|
|
|
|
|
2010-05-30 20:10:41 +02:00
|
|
|
select * from dfunc(1,2,d := 3);
|
2009-10-08 04:39:25 +02:00
|
|
|
a | b | c | d
|
|
|
|
---+---+---+---
|
|
|
|
1 | 2 | 0 | 3
|
|
|
|
(1 row)
|
|
|
|
|
2010-05-30 20:10:41 +02:00
|
|
|
select * from dfunc(x := 20, b := 10, x := 30); -- fail, duplicate name
|
2009-10-08 04:39:25 +02:00
|
|
|
ERROR: argument name "x" used more than once
|
2010-05-30 20:10:41 +02:00
|
|
|
LINE 1: select * from dfunc(x := 20, b := 10, x := 30);
|
|
|
|
^
|
|
|
|
select * from dfunc(10, b := 20, 30); -- fail, named args must be last
|
2009-10-08 04:39:25 +02:00
|
|
|
ERROR: positional argument cannot follow named argument
|
2010-05-30 20:10:41 +02:00
|
|
|
LINE 1: select * from dfunc(10, b := 20, 30);
|
2009-10-08 04:39:25 +02:00
|
|
|
^
|
2010-05-30 20:10:41 +02:00
|
|
|
select * from dfunc(x := 10, b := 20, c := 30); -- fail, unknown param
|
2015-05-01 15:37:10 +02:00
|
|
|
ERROR: function dfunc(x => integer, b => integer, c => integer) does not exist
|
2010-05-30 20:10:41 +02:00
|
|
|
LINE 1: select * from dfunc(x := 10, b := 20, c := 30);
|
2009-10-08 04:39:25 +02:00
|
|
|
^
|
|
|
|
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
|
2010-05-30 20:10:41 +02:00
|
|
|
select * from dfunc(10, 10, a := 20); -- fail, a overlaps positional parameter
|
2015-05-01 15:37:10 +02:00
|
|
|
ERROR: function dfunc(integer, integer, a => integer) does not exist
|
2010-05-30 20:10:41 +02:00
|
|
|
LINE 1: select * from dfunc(10, 10, a := 20);
|
2009-10-08 04:39:25 +02:00
|
|
|
^
|
|
|
|
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
|
2010-05-30 20:10:41 +02:00
|
|
|
select * from dfunc(1,c := 2,d := 3); -- fail, no value for b
|
2015-05-01 15:37:10 +02:00
|
|
|
ERROR: function dfunc(integer, c => integer, d => integer) does not exist
|
2010-05-30 20:10:41 +02:00
|
|
|
LINE 1: select * from dfunc(1,c := 2,d := 3);
|
2009-10-08 04:39:25 +02:00
|
|
|
^
|
|
|
|
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
|
|
|
|
drop function dfunc(int, int, int, int);
|
|
|
|
-- test with different parameter types
|
|
|
|
create function dfunc(a varchar, b numeric, c date = current_date)
|
|
|
|
returns table (a varchar, b numeric, c date) as $$
|
|
|
|
select $1, $2, $3;
|
|
|
|
$$ language sql;
|
|
|
|
select (dfunc('Hello World', 20, '2009-07-25'::date)).*;
|
|
|
|
a | b | c
|
|
|
|
-------------+----+------------
|
|
|
|
Hello World | 20 | 07-25-2009
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select * from dfunc('Hello World', 20, '2009-07-25'::date);
|
|
|
|
a | b | c
|
|
|
|
-------------+----+------------
|
|
|
|
Hello World | 20 | 07-25-2009
|
|
|
|
(1 row)
|
|
|
|
|
2010-05-30 20:10:41 +02:00
|
|
|
select * from dfunc(c := '2009-07-25'::date, a := 'Hello World', b := 20);
|
2009-10-08 04:39:25 +02:00
|
|
|
a | b | c
|
|
|
|
-------------+----+------------
|
|
|
|
Hello World | 20 | 07-25-2009
|
|
|
|
(1 row)
|
|
|
|
|
2010-05-30 20:10:41 +02:00
|
|
|
select * from dfunc('Hello World', b := 20, c := '2009-07-25'::date);
|
2009-10-08 04:39:25 +02:00
|
|
|
a | b | c
|
|
|
|
-------------+----+------------
|
|
|
|
Hello World | 20 | 07-25-2009
|
|
|
|
(1 row)
|
|
|
|
|
2010-05-30 20:10:41 +02:00
|
|
|
select * from dfunc('Hello World', c := '2009-07-25'::date, b := 20);
|
2009-10-08 04:39:25 +02:00
|
|
|
a | b | c
|
|
|
|
-------------+----+------------
|
|
|
|
Hello World | 20 | 07-25-2009
|
|
|
|
(1 row)
|
|
|
|
|
2010-05-30 20:10:41 +02:00
|
|
|
select * from dfunc('Hello World', c := 20, b := '2009-07-25'::date); -- fail
|
2015-05-01 15:37:10 +02:00
|
|
|
ERROR: function dfunc(unknown, c => integer, b => date) does not exist
|
2010-05-30 20:10:41 +02:00
|
|
|
LINE 1: select * from dfunc('Hello World', c := 20, b := '2009-07-25...
|
2009-10-08 04:39:25 +02:00
|
|
|
^
|
|
|
|
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
|
|
|
|
drop function dfunc(varchar, numeric, date);
|
|
|
|
-- test out parameters with named params
|
|
|
|
create function dfunc(a varchar = 'def a', out _a varchar, c numeric = NULL, out _c numeric)
|
|
|
|
returns record as $$
|
|
|
|
select $1, $2;
|
|
|
|
$$ language sql;
|
|
|
|
select (dfunc()).*;
|
|
|
|
_a | _c
|
|
|
|
-------+----
|
|
|
|
def a |
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select * from dfunc();
|
|
|
|
_a | _c
|
|
|
|
-------+----
|
|
|
|
def a |
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select * from dfunc('Hello', 100);
|
|
|
|
_a | _c
|
|
|
|
-------+-----
|
|
|
|
Hello | 100
|
|
|
|
(1 row)
|
|
|
|
|
2010-05-30 20:10:41 +02:00
|
|
|
select * from dfunc(a := 'Hello', c := 100);
|
2009-10-08 04:39:25 +02:00
|
|
|
_a | _c
|
|
|
|
-------+-----
|
|
|
|
Hello | 100
|
|
|
|
(1 row)
|
|
|
|
|
2010-05-30 20:10:41 +02:00
|
|
|
select * from dfunc(c := 100, a := 'Hello');
|
2009-10-08 04:39:25 +02:00
|
|
|
_a | _c
|
|
|
|
-------+-----
|
|
|
|
Hello | 100
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select * from dfunc('Hello');
|
|
|
|
_a | _c
|
|
|
|
-------+----
|
|
|
|
Hello |
|
|
|
|
(1 row)
|
|
|
|
|
2010-05-30 20:10:41 +02:00
|
|
|
select * from dfunc('Hello', c := 100);
|
2009-10-08 04:39:25 +02:00
|
|
|
_a | _c
|
|
|
|
-------+-----
|
|
|
|
Hello | 100
|
|
|
|
(1 row)
|
|
|
|
|
2010-05-30 20:10:41 +02:00
|
|
|
select * from dfunc(c := 100);
|
2009-10-08 04:39:25 +02:00
|
|
|
_a | _c
|
|
|
|
-------+-----
|
|
|
|
def a | 100
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- fail, can no longer change an input parameter's name
|
|
|
|
create or replace function dfunc(a varchar = 'def a', out _a varchar, x numeric = NULL, out _c numeric)
|
|
|
|
returns record as $$
|
|
|
|
select $1, $2;
|
|
|
|
$$ language sql;
|
|
|
|
ERROR: cannot change name of input parameter "c"
|
2012-06-26 19:33:23 +02:00
|
|
|
HINT: Use DROP FUNCTION dfunc(character varying,numeric) first.
|
2009-10-08 04:39:25 +02:00
|
|
|
create or replace function dfunc(a varchar = 'def a', out _a varchar, numeric = NULL, out _c numeric)
|
|
|
|
returns record as $$
|
|
|
|
select $1, $2;
|
|
|
|
$$ language sql;
|
|
|
|
ERROR: cannot change name of input parameter "c"
|
2012-06-26 19:33:23 +02:00
|
|
|
HINT: Use DROP FUNCTION dfunc(character varying,numeric) first.
|
2009-10-08 04:39:25 +02:00
|
|
|
drop function dfunc(varchar, numeric);
|
|
|
|
--fail, named parameters are not unique
|
Clean up duplicate table and function names in regression tests.
Many of the objects we create during the regression tests are put in the
public schema, so that using the same names in different regression tests
creates a hazard of test failures if any two such scripts run concurrently.
This patch cleans up a bunch of latent hazards of that sort, as well as two
live hazards.
The current situation in this regard is far worse than it was a year or two
back, because practically all of the partitioning-related test cases have
reused table names with enthusiasm. I despaired of cleaning up that mess
within the five most-affected tests (create_table, alter_table, insert,
update, inherit); fortunately those don't run concurrently.
Other than partitioning problems, most of the issues boil down to using
names like "foo", "bar", "tmp", etc, without thought for the fact that
other test scripts might use similar names concurrently. I've made an
effort to make all such names more specific.
One of the live hazards was that commit 7421f4b8 caused with.sql to
create a table named "test", conflicting with a similarly-named table
in alter_table.sql; this was exposed in the buildfarm recently.
The other one was that join.sql and transactions.sql both create tables
named "foo" and "bar"; but join.sql's uses of those names date back
only to December or so.
Since commit 7421f4b8 was back-patched to v10, back-patch a minimal
fix for that problem. The rest of this is just future-proofing.
Discussion: https://postgr.es/m/4627.1521070268@sss.pgh.pa.us
2018-03-15 22:08:51 +01:00
|
|
|
create function testpolym(a int, a int) returns int as $$ select 1;$$ language sql;
|
2009-10-08 04:39:25 +02:00
|
|
|
ERROR: parameter name "a" used more than once
|
Clean up duplicate table and function names in regression tests.
Many of the objects we create during the regression tests are put in the
public schema, so that using the same names in different regression tests
creates a hazard of test failures if any two such scripts run concurrently.
This patch cleans up a bunch of latent hazards of that sort, as well as two
live hazards.
The current situation in this regard is far worse than it was a year or two
back, because practically all of the partitioning-related test cases have
reused table names with enthusiasm. I despaired of cleaning up that mess
within the five most-affected tests (create_table, alter_table, insert,
update, inherit); fortunately those don't run concurrently.
Other than partitioning problems, most of the issues boil down to using
names like "foo", "bar", "tmp", etc, without thought for the fact that
other test scripts might use similar names concurrently. I've made an
effort to make all such names more specific.
One of the live hazards was that commit 7421f4b8 caused with.sql to
create a table named "test", conflicting with a similarly-named table
in alter_table.sql; this was exposed in the buildfarm recently.
The other one was that join.sql and transactions.sql both create tables
named "foo" and "bar"; but join.sql's uses of those names date back
only to December or so.
Since commit 7421f4b8 was back-patched to v10, back-patch a minimal
fix for that problem. The rest of this is just future-proofing.
Discussion: https://postgr.es/m/4627.1521070268@sss.pgh.pa.us
2018-03-15 22:08:51 +01:00
|
|
|
create function testpolym(int, out a int, out a int) returns int as $$ select 1;$$ language sql;
|
2009-10-08 04:39:25 +02:00
|
|
|
ERROR: parameter name "a" used more than once
|
Clean up duplicate table and function names in regression tests.
Many of the objects we create during the regression tests are put in the
public schema, so that using the same names in different regression tests
creates a hazard of test failures if any two such scripts run concurrently.
This patch cleans up a bunch of latent hazards of that sort, as well as two
live hazards.
The current situation in this regard is far worse than it was a year or two
back, because practically all of the partitioning-related test cases have
reused table names with enthusiasm. I despaired of cleaning up that mess
within the five most-affected tests (create_table, alter_table, insert,
update, inherit); fortunately those don't run concurrently.
Other than partitioning problems, most of the issues boil down to using
names like "foo", "bar", "tmp", etc, without thought for the fact that
other test scripts might use similar names concurrently. I've made an
effort to make all such names more specific.
One of the live hazards was that commit 7421f4b8 caused with.sql to
create a table named "test", conflicting with a similarly-named table
in alter_table.sql; this was exposed in the buildfarm recently.
The other one was that join.sql and transactions.sql both create tables
named "foo" and "bar"; but join.sql's uses of those names date back
only to December or so.
Since commit 7421f4b8 was back-patched to v10, back-patch a minimal
fix for that problem. The rest of this is just future-proofing.
Discussion: https://postgr.es/m/4627.1521070268@sss.pgh.pa.us
2018-03-15 22:08:51 +01:00
|
|
|
create function testpolym(out a int, inout a int) returns int as $$ select 1;$$ language sql;
|
2009-10-08 04:39:25 +02:00
|
|
|
ERROR: parameter name "a" used more than once
|
Clean up duplicate table and function names in regression tests.
Many of the objects we create during the regression tests are put in the
public schema, so that using the same names in different regression tests
creates a hazard of test failures if any two such scripts run concurrently.
This patch cleans up a bunch of latent hazards of that sort, as well as two
live hazards.
The current situation in this regard is far worse than it was a year or two
back, because practically all of the partitioning-related test cases have
reused table names with enthusiasm. I despaired of cleaning up that mess
within the five most-affected tests (create_table, alter_table, insert,
update, inherit); fortunately those don't run concurrently.
Other than partitioning problems, most of the issues boil down to using
names like "foo", "bar", "tmp", etc, without thought for the fact that
other test scripts might use similar names concurrently. I've made an
effort to make all such names more specific.
One of the live hazards was that commit 7421f4b8 caused with.sql to
create a table named "test", conflicting with a similarly-named table
in alter_table.sql; this was exposed in the buildfarm recently.
The other one was that join.sql and transactions.sql both create tables
named "foo" and "bar"; but join.sql's uses of those names date back
only to December or so.
Since commit 7421f4b8 was back-patched to v10, back-patch a minimal
fix for that problem. The rest of this is just future-proofing.
Discussion: https://postgr.es/m/4627.1521070268@sss.pgh.pa.us
2018-03-15 22:08:51 +01:00
|
|
|
create function testpolym(a int, inout a int) returns int as $$ select 1;$$ language sql;
|
2009-10-08 04:39:25 +02:00
|
|
|
ERROR: parameter name "a" used more than once
|
|
|
|
-- valid
|
Clean up duplicate table and function names in regression tests.
Many of the objects we create during the regression tests are put in the
public schema, so that using the same names in different regression tests
creates a hazard of test failures if any two such scripts run concurrently.
This patch cleans up a bunch of latent hazards of that sort, as well as two
live hazards.
The current situation in this regard is far worse than it was a year or two
back, because practically all of the partitioning-related test cases have
reused table names with enthusiasm. I despaired of cleaning up that mess
within the five most-affected tests (create_table, alter_table, insert,
update, inherit); fortunately those don't run concurrently.
Other than partitioning problems, most of the issues boil down to using
names like "foo", "bar", "tmp", etc, without thought for the fact that
other test scripts might use similar names concurrently. I've made an
effort to make all such names more specific.
One of the live hazards was that commit 7421f4b8 caused with.sql to
create a table named "test", conflicting with a similarly-named table
in alter_table.sql; this was exposed in the buildfarm recently.
The other one was that join.sql and transactions.sql both create tables
named "foo" and "bar"; but join.sql's uses of those names date back
only to December or so.
Since commit 7421f4b8 was back-patched to v10, back-patch a minimal
fix for that problem. The rest of this is just future-proofing.
Discussion: https://postgr.es/m/4627.1521070268@sss.pgh.pa.us
2018-03-15 22:08:51 +01:00
|
|
|
create function testpolym(a int, out a int) returns int as $$ select $1;$$ language sql;
|
|
|
|
select testpolym(37);
|
|
|
|
testpolym
|
|
|
|
-----------
|
|
|
|
37
|
2009-10-08 04:39:25 +02:00
|
|
|
(1 row)
|
|
|
|
|
Clean up duplicate table and function names in regression tests.
Many of the objects we create during the regression tests are put in the
public schema, so that using the same names in different regression tests
creates a hazard of test failures if any two such scripts run concurrently.
This patch cleans up a bunch of latent hazards of that sort, as well as two
live hazards.
The current situation in this regard is far worse than it was a year or two
back, because practically all of the partitioning-related test cases have
reused table names with enthusiasm. I despaired of cleaning up that mess
within the five most-affected tests (create_table, alter_table, insert,
update, inherit); fortunately those don't run concurrently.
Other than partitioning problems, most of the issues boil down to using
names like "foo", "bar", "tmp", etc, without thought for the fact that
other test scripts might use similar names concurrently. I've made an
effort to make all such names more specific.
One of the live hazards was that commit 7421f4b8 caused with.sql to
create a table named "test", conflicting with a similarly-named table
in alter_table.sql; this was exposed in the buildfarm recently.
The other one was that join.sql and transactions.sql both create tables
named "foo" and "bar"; but join.sql's uses of those names date back
only to December or so.
Since commit 7421f4b8 was back-patched to v10, back-patch a minimal
fix for that problem. The rest of this is just future-proofing.
Discussion: https://postgr.es/m/4627.1521070268@sss.pgh.pa.us
2018-03-15 22:08:51 +01:00
|
|
|
drop function testpolym(int);
|
|
|
|
create function testpolym(a int) returns table(a int) as $$ select $1;$$ language sql;
|
|
|
|
select * from testpolym(37);
|
2009-10-08 04:39:25 +02:00
|
|
|
a
|
|
|
|
----
|
|
|
|
37
|
|
|
|
(1 row)
|
|
|
|
|
Clean up duplicate table and function names in regression tests.
Many of the objects we create during the regression tests are put in the
public schema, so that using the same names in different regression tests
creates a hazard of test failures if any two such scripts run concurrently.
This patch cleans up a bunch of latent hazards of that sort, as well as two
live hazards.
The current situation in this regard is far worse than it was a year or two
back, because practically all of the partitioning-related test cases have
reused table names with enthusiasm. I despaired of cleaning up that mess
within the five most-affected tests (create_table, alter_table, insert,
update, inherit); fortunately those don't run concurrently.
Other than partitioning problems, most of the issues boil down to using
names like "foo", "bar", "tmp", etc, without thought for the fact that
other test scripts might use similar names concurrently. I've made an
effort to make all such names more specific.
One of the live hazards was that commit 7421f4b8 caused with.sql to
create a table named "test", conflicting with a similarly-named table
in alter_table.sql; this was exposed in the buildfarm recently.
The other one was that join.sql and transactions.sql both create tables
named "foo" and "bar"; but join.sql's uses of those names date back
only to December or so.
Since commit 7421f4b8 was back-patched to v10, back-patch a minimal
fix for that problem. The rest of this is just future-proofing.
Discussion: https://postgr.es/m/4627.1521070268@sss.pgh.pa.us
2018-03-15 22:08:51 +01:00
|
|
|
drop function testpolym(int);
|
2009-10-08 04:39:25 +02:00
|
|
|
-- test polymorphic params and defaults
|
|
|
|
create function dfunc(a anyelement, b anyelement = null, flag bool = true)
|
|
|
|
returns anyelement as $$
|
|
|
|
select case when $3 then $1 else $2 end;
|
|
|
|
$$ language sql;
|
|
|
|
select dfunc(1,2);
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc('a'::text, 'b'); -- positional notation with default
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
a
|
|
|
|
(1 row)
|
|
|
|
|
2010-05-30 20:10:41 +02:00
|
|
|
select dfunc(a := 1, b := 2);
|
2009-10-08 04:39:25 +02:00
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
2010-05-30 20:10:41 +02:00
|
|
|
select dfunc(a := 'a'::text, b := 'b');
|
2009-10-08 04:39:25 +02:00
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
a
|
|
|
|
(1 row)
|
|
|
|
|
2010-05-30 20:10:41 +02:00
|
|
|
select dfunc(a := 'a'::text, b := 'b', flag := false); -- named notation
|
2009-10-08 04:39:25 +02:00
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
b
|
|
|
|
(1 row)
|
|
|
|
|
2010-05-30 20:10:41 +02:00
|
|
|
select dfunc(b := 'b'::text, a := 'a'); -- named notation with default
|
2009-10-08 04:39:25 +02:00
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
a
|
|
|
|
(1 row)
|
|
|
|
|
2010-05-30 20:10:41 +02:00
|
|
|
select dfunc(a := 'a'::text, flag := true); -- named notation with default
|
2009-10-08 04:39:25 +02:00
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
a
|
|
|
|
(1 row)
|
|
|
|
|
2010-05-30 20:10:41 +02:00
|
|
|
select dfunc(a := 'a'::text, flag := false); -- named notation with default
|
2009-10-08 04:39:25 +02:00
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
2010-05-30 20:10:41 +02:00
|
|
|
select dfunc(b := 'b'::text, a := 'a', flag := true); -- named notation
|
2009-10-08 04:39:25 +02:00
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
a
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc('a'::text, 'b', false); -- full positional notation
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
b
|
|
|
|
(1 row)
|
|
|
|
|
2010-05-30 20:10:41 +02:00
|
|
|
select dfunc('a'::text, 'b', flag := false); -- mixed notation
|
2009-10-08 04:39:25 +02:00
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
b
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc('a'::text, 'b', true); -- full positional notation
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
a
|
|
|
|
(1 row)
|
|
|
|
|
2010-05-30 20:10:41 +02:00
|
|
|
select dfunc('a'::text, 'b', flag := true); -- mixed notation
|
2009-10-08 04:39:25 +02:00
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
a
|
|
|
|
(1 row)
|
|
|
|
|
Allow named parameters to be specified using => in addition to :=
SQL has standardized on => as the use of to specify named parameters,
and we've wanted for many years to support the same syntax ourselves,
but this has been complicated by the possible use of => as an operator
name. In PostgreSQL 9.0, we began emitting a warning when an operator
named => was defined, and in PostgreSQL 9.2, we stopped shipping a
=>(text, text) operator as part of hstore. By the time the next major
version of PostgreSQL is released, => will have been deprecated for a
full five years, so hopefully there won't be too many people still
relying on it. We continue to support := for compatibility with
previous PostgreSQL releases.
Pavel Stehule, reviewed by Petr Jelinek, with a few documentation
tweaks by me.
2015-03-10 15:59:11 +01:00
|
|
|
-- ansi/sql syntax
|
|
|
|
select dfunc(a => 1, b => 2);
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc(a => 'a'::text, b => 'b');
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
a
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc(a => 'a'::text, b => 'b', flag => false); -- named notation
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
b
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc(b => 'b'::text, a => 'a'); -- named notation with default
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
a
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc(a => 'a'::text, flag => true); -- named notation with default
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
a
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc(a => 'a'::text, flag => false); -- named notation with default
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc(b => 'b'::text, a => 'a', flag => true); -- named notation
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
a
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc('a'::text, 'b', false); -- full positional notation
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
b
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc('a'::text, 'b', flag => false); -- mixed notation
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
b
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc('a'::text, 'b', true); -- full positional notation
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
a
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc('a'::text, 'b', flag => true); -- mixed notation
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
a
|
|
|
|
(1 row)
|
|
|
|
|
Fix lexing of standard multi-character operators in edge cases.
Commits c6b3c939b (which fixed the precedence of >=, <=, <> operators)
and 865f14a2d (which added support for the standard => notation for
named arguments) created a class of lexer tokens which look like
multi-character operators but which have their own token IDs distinct
from Op. However, longest-match rules meant that following any of
these tokens with another operator character, as in (1<>-1), would
cause them to be incorrectly returned as Op.
The error here isn't immediately obvious, because the parser would
usually still find the correct operator via the Op token, but there
were more subtle problems:
1. If immediately followed by a comment or +-, >= <= <> would be given
the old precedence of Op rather than the correct new precedence;
2. If followed by a comment, != would be returned as Op rather than as
NOT_EQUAL, causing it not to be found at all;
3. If followed by a comment or +-, the => token for named arguments
would be lexed as Op, causing the argument to be mis-parsed as a
simple expression, usually causing an error.
Fix by explicitly checking for the operators in the {operator} code
block in addition to all the existing special cases there.
Backpatch to 9.5 where the problem was introduced.
Analysis and patch by me; review by Tom Lane.
Discussion: https://postgr.es/m/87va851ppl.fsf@news-spur.riddles.org.uk
2018-08-23 19:29:18 +02:00
|
|
|
-- this tests lexer edge cases around =>
|
|
|
|
select dfunc(a =>-1);
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
-1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc(a =>+1);
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc(a =>/**/1);
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select dfunc(a =>--comment to be removed by psql
|
|
|
|
1);
|
|
|
|
dfunc
|
|
|
|
-------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- need DO to protect the -- from psql
|
|
|
|
do $$
|
|
|
|
declare r integer;
|
|
|
|
begin
|
|
|
|
select dfunc(a=>-- comment
|
|
|
|
1) into r;
|
|
|
|
raise info 'r = %', r;
|
|
|
|
end;
|
|
|
|
$$;
|
|
|
|
INFO: r = 1
|
2009-10-08 04:39:25 +02:00
|
|
|
-- check reverse-listing of named-arg calls
|
|
|
|
CREATE VIEW dfview AS
|
|
|
|
SELECT q1, q2,
|
2010-05-30 20:10:41 +02:00
|
|
|
dfunc(q1,q2, flag := q1>q2) as c3,
|
|
|
|
dfunc(q1, flag := q1<q2, b := q2) as c4
|
2009-10-08 04:39:25 +02:00
|
|
|
FROM int8_tbl;
|
|
|
|
select * from dfview;
|
|
|
|
q1 | q2 | c3 | c4
|
|
|
|
------------------+-------------------+------------------+-------------------
|
|
|
|
123 | 456 | 456 | 123
|
|
|
|
123 | 4567890123456789 | 4567890123456789 | 123
|
|
|
|
4567890123456789 | 123 | 4567890123456789 | 123
|
|
|
|
4567890123456789 | 4567890123456789 | 4567890123456789 | 4567890123456789
|
|
|
|
4567890123456789 | -4567890123456789 | 4567890123456789 | -4567890123456789
|
|
|
|
(5 rows)
|
|
|
|
|
2009-11-03 15:52:10 +01:00
|
|
|
\d+ dfview
|
2016-11-03 17:00:00 +01:00
|
|
|
View "public.dfview"
|
|
|
|
Column | Type | Collation | Nullable | Default | Storage | Description
|
|
|
|
--------+--------+-----------+----------+---------+---------+-------------
|
|
|
|
q1 | bigint | | | | plain |
|
|
|
|
q2 | bigint | | | | plain |
|
|
|
|
c3 | bigint | | | | plain |
|
|
|
|
c4 | bigint | | | | plain |
|
2009-10-08 04:39:25 +02:00
|
|
|
View definition:
|
2023-01-18 19:23:57 +01:00
|
|
|
SELECT q1,
|
|
|
|
q2,
|
|
|
|
dfunc(q1, q2, flag => q1 > q2) AS c3,
|
|
|
|
dfunc(q1, flag => q1 < q2, b => q2) AS c4
|
2009-10-08 04:39:25 +02:00
|
|
|
FROM int8_tbl;
|
|
|
|
|
|
|
|
drop view dfview;
|
|
|
|
drop function dfunc(anyelement, anyelement, bool);
|
Introduce "anycompatible" family of polymorphic types.
This patch adds the pseudo-types anycompatible, anycompatiblearray,
anycompatiblenonarray, and anycompatiblerange. They work much like
anyelement, anyarray, anynonarray, and anyrange respectively, except
that the actual input values need not match precisely in type.
Instead, if we can find a common supertype (using the same rules
as for UNION/CASE type resolution), then the parser automatically
promotes the input values to that type. For example,
"myfunc(anycompatible, anycompatible)" can match a call with one
integer and one bigint argument, with the integer automatically
promoted to bigint. With anyelement in the definition, the user
would have had to cast the integer explicitly.
The new types also provide a second, independent set of type variables
for function matching; thus with "myfunc(anyelement, anyelement,
anycompatible) returns anycompatible" the first two arguments are
constrained to be the same type, but the third can be some other
type, and the result has the type of the third argument. The need
for more than one set of type variables was foreseen back when we
first invented the polymorphic types, but we never did anything
about it.
Pavel Stehule, revised a bit by me
Discussion: https://postgr.es/m/CAFj8pRDna7VqNi8gR+Tt2Ktmz0cq5G93guc3Sbn_NVPLdXAkqA@mail.gmail.com
2020-03-19 16:43:11 +01:00
|
|
|
--
|
|
|
|
-- Tests for ANYCOMPATIBLE polymorphism family
|
|
|
|
--
|
|
|
|
create function anyctest(anycompatible, anycompatible)
|
|
|
|
returns anycompatible as $$
|
|
|
|
select greatest($1, $2)
|
|
|
|
$$ language sql;
|
|
|
|
select x, pg_typeof(x) from anyctest(11, 12) x;
|
|
|
|
x | pg_typeof
|
|
|
|
----+-----------
|
|
|
|
12 | integer
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x) from anyctest(11, 12.3) x;
|
|
|
|
x | pg_typeof
|
|
|
|
------+-----------
|
|
|
|
12.3 | numeric
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x) from anyctest(11, point(1,2)) x; -- fail
|
|
|
|
ERROR: function anyctest(integer, point) does not exist
|
|
|
|
LINE 1: select x, pg_typeof(x) from anyctest(11, point(1,2)) x;
|
|
|
|
^
|
|
|
|
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', '12.3') x; -- defaults to text
|
|
|
|
x | pg_typeof
|
|
|
|
------+-----------
|
|
|
|
12.3 | text
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
drop function anyctest(anycompatible, anycompatible);
|
|
|
|
create function anyctest(anycompatible, anycompatible)
|
|
|
|
returns anycompatiblearray as $$
|
|
|
|
select array[$1, $2]
|
|
|
|
$$ language sql;
|
|
|
|
select x, pg_typeof(x) from anyctest(11, 12) x;
|
|
|
|
x | pg_typeof
|
|
|
|
---------+-----------
|
|
|
|
{11,12} | integer[]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x) from anyctest(11, 12.3) x;
|
|
|
|
x | pg_typeof
|
|
|
|
-----------+-----------
|
|
|
|
{11,12.3} | numeric[]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x) from anyctest(11, array[1,2]) x; -- fail
|
|
|
|
ERROR: function anyctest(integer, integer[]) does not exist
|
|
|
|
LINE 1: select x, pg_typeof(x) from anyctest(11, array[1,2]) x;
|
|
|
|
^
|
|
|
|
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
|
|
|
|
drop function anyctest(anycompatible, anycompatible);
|
|
|
|
create function anyctest(anycompatible, anycompatiblearray)
|
|
|
|
returns anycompatiblearray as $$
|
|
|
|
select array[$1] || $2
|
|
|
|
$$ language sql;
|
|
|
|
select x, pg_typeof(x) from anyctest(11, array[12]) x;
|
|
|
|
x | pg_typeof
|
|
|
|
---------+-----------
|
|
|
|
{11,12} | integer[]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x) from anyctest(11, array[12.3]) x;
|
|
|
|
x | pg_typeof
|
|
|
|
-----------+-----------
|
|
|
|
{11,12.3} | numeric[]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x) from anyctest(12.3, array[13]) x;
|
|
|
|
x | pg_typeof
|
|
|
|
-----------+-----------
|
|
|
|
{12.3,13} | numeric[]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x) from anyctest(12.3, '{13,14.4}') x;
|
|
|
|
x | pg_typeof
|
|
|
|
----------------+-----------
|
|
|
|
{12.3,13,14.4} | numeric[]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x) from anyctest(11, array[point(1,2)]) x; -- fail
|
|
|
|
ERROR: function anyctest(integer, point[]) does not exist
|
|
|
|
LINE 1: select x, pg_typeof(x) from anyctest(11, array[point(1,2)]) ...
|
|
|
|
^
|
|
|
|
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, 12) x; -- fail
|
|
|
|
ERROR: function anyctest(integer, integer) does not exist
|
|
|
|
LINE 1: select x, pg_typeof(x) from anyctest(11, 12) x;
|
|
|
|
^
|
|
|
|
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
|
|
|
|
drop function anyctest(anycompatible, anycompatiblearray);
|
|
|
|
create function anyctest(anycompatible, anycompatiblerange)
|
|
|
|
returns anycompatiblerange as $$
|
|
|
|
select $2
|
|
|
|
$$ language sql;
|
|
|
|
select x, pg_typeof(x) from anyctest(11, int4range(4,7)) x;
|
|
|
|
x | pg_typeof
|
|
|
|
-------+-----------
|
|
|
|
[4,7) | int4range
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x) from anyctest(11, numrange(4,7)) x;
|
|
|
|
x | pg_typeof
|
|
|
|
-------+-----------
|
|
|
|
[4,7) | numrange
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x) from anyctest(11, 12) x; -- fail
|
|
|
|
ERROR: function anyctest(integer, integer) does not exist
|
|
|
|
LINE 1: select x, pg_typeof(x) from anyctest(11, 12) x;
|
|
|
|
^
|
|
|
|
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, int4range(4,7)) x; -- fail
|
|
|
|
ERROR: function anyctest(numeric, int4range) does not exist
|
|
|
|
LINE 1: select x, pg_typeof(x) from anyctest(11.2, int4range(4,7)) x...
|
|
|
|
^
|
|
|
|
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
|
|
|
|
ERROR: could not determine polymorphic type anycompatiblerange because input has type unknown
|
|
|
|
drop function anyctest(anycompatible, anycompatiblerange);
|
|
|
|
create function anyctest(anycompatiblerange, anycompatiblerange)
|
|
|
|
returns anycompatible as $$
|
|
|
|
select lower($1) + upper($2)
|
|
|
|
$$ language sql;
|
|
|
|
select x, pg_typeof(x) from anyctest(int4range(11,12), int4range(4,7)) x;
|
|
|
|
x | pg_typeof
|
|
|
|
----+-----------
|
|
|
|
18 | integer
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x) from anyctest(int4range(11,12), numrange(4,7)) x; -- fail
|
|
|
|
ERROR: function anyctest(int4range, numrange) does not exist
|
|
|
|
LINE 1: select x, pg_typeof(x) from anyctest(int4range(11,12), numra...
|
|
|
|
^
|
|
|
|
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
|
|
|
|
drop function anyctest(anycompatiblerange, anycompatiblerange);
|
|
|
|
-- fail, can't infer result type:
|
|
|
|
create function anyctest(anycompatible)
|
|
|
|
returns anycompatiblerange as $$
|
|
|
|
select $1
|
|
|
|
$$ language sql;
|
|
|
|
ERROR: cannot determine result data type
|
Multirange datatypes
Multiranges are basically sorted arrays of non-overlapping ranges with
set-theoretic operations defined over them.
Since v14, each range type automatically gets a corresponding multirange
datatype. There are both manual and automatic mechanisms for naming multirange
types. Once can specify multirange type name using multirange_type_name
attribute in CREATE TYPE. Otherwise, a multirange type name is generated
automatically. If the range type name contains "range" then we change that to
"multirange". Otherwise, we add "_multirange" to the end.
Implementation of multiranges comes with a space-efficient internal
representation format, which evades extra paddings and duplicated storage of
oids. Altogether this format allows fetching a particular range by its index
in O(n).
Statistic gathering and selectivity estimation are implemented for multiranges.
For this purpose, stored multirange is approximated as union range without gaps.
This field will likely need improvements in the future.
Catversion is bumped.
Discussion: https://postgr.es/m/CALNJ-vSUpQ_Y%3DjXvTxt1VYFztaBSsWVXeF1y6gTYQ4bOiWDLgQ%40mail.gmail.com
Discussion: https://postgr.es/m/a0b8026459d1e6167933be2104a6174e7d40d0ab.camel%40j-davis.com#fe7218c83b08068bfffb0c5293eceda0
Author: Paul Jungwirth, revised by me
Reviewed-by: David Fetter, Corey Huinker, Jeff Davis, Pavel Stehule
Reviewed-by: Alvaro Herrera, Tom Lane, Isaac Morland, David G. Johnston
Reviewed-by: Zhihong Yu, Alexander Korotkov
2020-12-20 05:20:33 +01:00
|
|
|
DETAIL: A result of type anycompatiblerange requires at least one input of type anycompatiblerange or anycompatiblemultirange.
|
|
|
|
create function anyctest(anycompatible, anycompatiblemultirange)
|
|
|
|
returns anycompatiblemultirange as $$
|
|
|
|
select $2
|
|
|
|
$$ language sql;
|
|
|
|
select x, pg_typeof(x) from anyctest(11, multirange(int4range(4,7))) x;
|
|
|
|
x | pg_typeof
|
|
|
|
---------+----------------
|
|
|
|
{[4,7)} | int4multirange
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x) from anyctest(11, multirange(numrange(4,7))) x;
|
|
|
|
x | pg_typeof
|
|
|
|
---------+---------------
|
|
|
|
{[4,7)} | nummultirange
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x) from anyctest(11, 12) x; -- fail
|
|
|
|
ERROR: function anyctest(integer, integer) does not exist
|
|
|
|
LINE 1: select x, pg_typeof(x) from anyctest(11, 12) x;
|
|
|
|
^
|
|
|
|
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, multirange(int4range(4,7))) x; -- fail
|
|
|
|
ERROR: function anyctest(numeric, int4multirange) does not exist
|
|
|
|
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.
|
|
|
|
select x, pg_typeof(x) from anyctest(11.2, '{[4,7)}') x; -- fail
|
2021-07-27 21:01:49 +02:00
|
|
|
ERROR: could not determine polymorphic type anycompatiblemultirange because input has type unknown
|
Multirange datatypes
Multiranges are basically sorted arrays of non-overlapping ranges with
set-theoretic operations defined over them.
Since v14, each range type automatically gets a corresponding multirange
datatype. There are both manual and automatic mechanisms for naming multirange
types. Once can specify multirange type name using multirange_type_name
attribute in CREATE TYPE. Otherwise, a multirange type name is generated
automatically. If the range type name contains "range" then we change that to
"multirange". Otherwise, we add "_multirange" to the end.
Implementation of multiranges comes with a space-efficient internal
representation format, which evades extra paddings and duplicated storage of
oids. Altogether this format allows fetching a particular range by its index
in O(n).
Statistic gathering and selectivity estimation are implemented for multiranges.
For this purpose, stored multirange is approximated as union range without gaps.
This field will likely need improvements in the future.
Catversion is bumped.
Discussion: https://postgr.es/m/CALNJ-vSUpQ_Y%3DjXvTxt1VYFztaBSsWVXeF1y6gTYQ4bOiWDLgQ%40mail.gmail.com
Discussion: https://postgr.es/m/a0b8026459d1e6167933be2104a6174e7d40d0ab.camel%40j-davis.com#fe7218c83b08068bfffb0c5293eceda0
Author: Paul Jungwirth, revised by me
Reviewed-by: David Fetter, Corey Huinker, Jeff Davis, Pavel Stehule
Reviewed-by: Alvaro Herrera, Tom Lane, Isaac Morland, David G. Johnston
Reviewed-by: Zhihong Yu, Alexander Korotkov
2020-12-20 05:20:33 +01:00
|
|
|
drop function anyctest(anycompatible, anycompatiblemultirange);
|
|
|
|
create function anyctest(anycompatiblemultirange, anycompatiblemultirange)
|
|
|
|
returns anycompatible as $$
|
|
|
|
select lower($1) + upper($2)
|
|
|
|
$$ language sql;
|
|
|
|
select x, pg_typeof(x) from anyctest(multirange(int4range(11,12)), multirange(int4range(4,7))) x;
|
|
|
|
x | pg_typeof
|
|
|
|
----+-----------
|
|
|
|
18 | integer
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x) from anyctest(multirange(int4range(11,12)), multirange(numrange(4,7))) x; -- fail
|
|
|
|
ERROR: function anyctest(int4multirange, nummultirange) does not exist
|
|
|
|
LINE 1: select x, pg_typeof(x) from anyctest(multirange(int4range(11...
|
|
|
|
^
|
|
|
|
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
|
|
|
|
drop function anyctest(anycompatiblemultirange, anycompatiblemultirange);
|
|
|
|
-- fail, can't infer result type:
|
|
|
|
create function anyctest(anycompatible)
|
|
|
|
returns anycompatiblemultirange as $$
|
|
|
|
select $1
|
|
|
|
$$ language sql;
|
|
|
|
ERROR: cannot determine result data type
|
|
|
|
DETAIL: A result of type anycompatiblemultirange requires at least one input of type anycompatiblerange or anycompatiblemultirange.
|
Introduce "anycompatible" family of polymorphic types.
This patch adds the pseudo-types anycompatible, anycompatiblearray,
anycompatiblenonarray, and anycompatiblerange. They work much like
anyelement, anyarray, anynonarray, and anyrange respectively, except
that the actual input values need not match precisely in type.
Instead, if we can find a common supertype (using the same rules
as for UNION/CASE type resolution), then the parser automatically
promotes the input values to that type. For example,
"myfunc(anycompatible, anycompatible)" can match a call with one
integer and one bigint argument, with the integer automatically
promoted to bigint. With anyelement in the definition, the user
would have had to cast the integer explicitly.
The new types also provide a second, independent set of type variables
for function matching; thus with "myfunc(anyelement, anyelement,
anycompatible) returns anycompatible" the first two arguments are
constrained to be the same type, but the third can be some other
type, and the result has the type of the third argument. The need
for more than one set of type variables was foreseen back when we
first invented the polymorphic types, but we never did anything
about it.
Pavel Stehule, revised a bit by me
Discussion: https://postgr.es/m/CAFj8pRDna7VqNi8gR+Tt2Ktmz0cq5G93guc3Sbn_NVPLdXAkqA@mail.gmail.com
2020-03-19 16:43:11 +01:00
|
|
|
create function anyctest(anycompatiblenonarray, anycompatiblenonarray)
|
|
|
|
returns anycompatiblearray as $$
|
|
|
|
select array[$1, $2]
|
|
|
|
$$ language sql;
|
|
|
|
select x, pg_typeof(x) from anyctest(11, 12) x;
|
|
|
|
x | pg_typeof
|
|
|
|
---------+-----------
|
|
|
|
{11,12} | integer[]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x) from anyctest(11, 12.3) x;
|
|
|
|
x | pg_typeof
|
|
|
|
-----------+-----------
|
|
|
|
{11,12.3} | numeric[]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x) from anyctest(array[11], array[1,2]) x; -- fail
|
|
|
|
ERROR: function anyctest(integer[], integer[]) does not exist
|
|
|
|
LINE 1: select x, pg_typeof(x) from anyctest(array[11], array[1,2]) ...
|
|
|
|
^
|
|
|
|
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
|
|
|
|
drop function anyctest(anycompatiblenonarray, anycompatiblenonarray);
|
|
|
|
create function anyctest(a anyelement, b anyarray,
|
|
|
|
c anycompatible, d anycompatible)
|
|
|
|
returns anycompatiblearray as $$
|
|
|
|
select array[c, d]
|
|
|
|
$$ language sql;
|
|
|
|
select x, pg_typeof(x) from anyctest(11, array[1, 2], 42, 34.5) x;
|
|
|
|
x | pg_typeof
|
|
|
|
-----------+-----------
|
|
|
|
{42,34.5} | numeric[]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x) from anyctest(11, array[1, 2], point(1,2), point(3,4)) x;
|
|
|
|
x | pg_typeof
|
|
|
|
-------------------+-----------
|
|
|
|
{"(1,2)","(3,4)"} | point[]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x) from anyctest(11, '{1,2}', point(1,2), '(3,4)') x;
|
|
|
|
x | pg_typeof
|
|
|
|
-------------------+-----------
|
|
|
|
{"(1,2)","(3,4)"} | point[]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x) from anyctest(11, array[1, 2.2], 42, 34.5) x; -- fail
|
|
|
|
ERROR: function anyctest(integer, numeric[], integer, numeric) does not exist
|
|
|
|
LINE 1: select x, pg_typeof(x) from anyctest(11, array[1, 2.2], 42, ...
|
|
|
|
^
|
|
|
|
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
|
|
|
|
drop function anyctest(a anyelement, b anyarray,
|
|
|
|
c anycompatible, d anycompatible);
|
|
|
|
create function anyctest(variadic anycompatiblearray)
|
|
|
|
returns anycompatiblearray as $$
|
|
|
|
select $1
|
|
|
|
$$ language sql;
|
|
|
|
select x, pg_typeof(x) from anyctest(11, 12) x;
|
|
|
|
x | pg_typeof
|
|
|
|
---------+-----------
|
|
|
|
{11,12} | integer[]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x) from anyctest(11, 12.2) x;
|
|
|
|
x | pg_typeof
|
|
|
|
-----------+-----------
|
|
|
|
{11,12.2} | numeric[]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x) from anyctest(11, '12') x;
|
|
|
|
x | pg_typeof
|
|
|
|
---------+-----------
|
|
|
|
{11,12} | integer[]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x) from anyctest(11, '12.2') x; -- fail
|
|
|
|
ERROR: invalid input syntax for type integer: "12.2"
|
|
|
|
LINE 1: select x, pg_typeof(x) from anyctest(11, '12.2') x;
|
|
|
|
^
|
|
|
|
select x, pg_typeof(x) from anyctest(variadic array[11, 12]) x;
|
|
|
|
x | pg_typeof
|
|
|
|
---------+-----------
|
|
|
|
{11,12} | integer[]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
select x, pg_typeof(x) from anyctest(variadic array[11, 12.2]) x;
|
|
|
|
x | pg_typeof
|
|
|
|
-----------+-----------
|
|
|
|
{11,12.2} | numeric[]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
drop function anyctest(variadic anycompatiblearray);
|