Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita9d5f30

Browse files
committed
Restore enforce_generic_type_consistency's pre-8.3 behavior of allowing an
actual argument type of ANYARRAY to match an argument declared ANYARRAY,so long as ANYELEMENT etc aren't used. I had overlooked the fact that thisis a possible case while fixing bug #3852; but it is possible becausepg_statistic contains columns declared ANYARRAY. Per gripe from Corey Horton.
1 parentb8753e5 commita9d5f30

File tree

3 files changed

+46
-8
lines changed

3 files changed

+46
-8
lines changed

‎src/backend/parser/parse_coerce.c

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.171 2008/10/31 08:39:21 heikki Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.172 2008/12/14 19:45:52 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1424,6 +1424,15 @@ check_generic_type_consistency(Oid *actual_arg_types,
14241424
* arg types, and we can return ANYARRAY or ANYELEMENT as the result. (This
14251425
* case is currently used only to check compatibility of an aggregate's
14261426
* declaration with the underlying transfn.)
1427+
*
1428+
* A special case is that we could see ANYARRAY as an actual_arg_type even
1429+
* when allow_poly is false (this is possible only because pg_statistic has
1430+
* columns shown as anyarray in the catalogs). We allow this to match a
1431+
* declared ANYARRAY argument, but only if there is no ANYELEMENT argument
1432+
* or result (since we can't determine a specific element type to match to
1433+
* ANYELEMENT). Note this means that functions taking ANYARRAY had better
1434+
* behave sanely if applied to the pg_statistic columns; they can't just
1435+
* assume that successive inputs are of the same actual element type.
14271436
*/
14281437
Oid
14291438
enforce_generic_type_consistency(Oid*actual_arg_types,
@@ -1438,6 +1447,9 @@ enforce_generic_type_consistency(Oid *actual_arg_types,
14381447
Oidelem_typeid=InvalidOid;
14391448
Oidarray_typeid=InvalidOid;
14401449
Oidarray_typelem;
1450+
boolhave_anyelement= (rettype==ANYELEMENTOID||
1451+
rettype==ANYNONARRAYOID||
1452+
rettype==ANYENUMOID);
14411453
boolhave_anynonarray= (rettype==ANYNONARRAYOID);
14421454
boolhave_anyenum= (rettype==ANYENUMOID);
14431455

@@ -1454,7 +1466,7 @@ enforce_generic_type_consistency(Oid *actual_arg_types,
14541466
decl_type==ANYNONARRAYOID||
14551467
decl_type==ANYENUMOID)
14561468
{
1457-
have_generics= true;
1469+
have_generics=have_anyelement=true;
14581470
if (decl_type==ANYNONARRAYOID)
14591471
have_anynonarray= true;
14601472
elseif (decl_type==ANYENUMOID)
@@ -1506,12 +1518,20 @@ enforce_generic_type_consistency(Oid *actual_arg_types,
15061518
/* Get the element type based on the array type, if we have one */
15071519
if (OidIsValid(array_typeid))
15081520
{
1509-
array_typelem=get_element_type(array_typeid);
1510-
if (!OidIsValid(array_typelem))
1511-
ereport(ERROR,
1512-
(errcode(ERRCODE_DATATYPE_MISMATCH),
1513-
errmsg("argument declared \"anyarray\" is not an array but type %s",
1514-
format_type_be(array_typeid))));
1521+
if (array_typeid==ANYARRAYOID&& !have_anyelement)
1522+
{
1523+
/* Special case for ANYARRAY input: okay iff no ANYELEMENT */
1524+
array_typelem=InvalidOid;
1525+
}
1526+
else
1527+
{
1528+
array_typelem=get_element_type(array_typeid);
1529+
if (!OidIsValid(array_typelem))
1530+
ereport(ERROR,
1531+
(errcode(ERRCODE_DATATYPE_MISMATCH),
1532+
errmsg("argument declared \"anyarray\" is not an array but type %s",
1533+
format_type_be(array_typeid))));
1534+
}
15151535

15161536
if (!OidIsValid(elem_typeid))
15171537
{

‎src/test/regress/expected/polymorphism.out

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,17 @@ create aggregate build_group(int8, integer) (
613613
SFUNC = add_group,
614614
STYPE = int8[]
615615
);
616+
-- check that we can apply functions taking ANYARRAY to pg_stats
617+
select distinct array_ndims(histogram_bounds) from pg_stats
618+
where histogram_bounds is not null;
619+
array_ndims
620+
-------------
621+
1
622+
(1 row)
623+
624+
-- such functions must protect themselves if varying element type isn't OK
625+
select max(histogram_bounds) from pg_stats;
626+
ERROR: cannot compare arrays of different element types
616627
-- test variadic polymorphic functions
617628
create function myleast(variadic anyarray) returns anyelement as $$
618629
select min($1[i]) from generate_subscripts($1,1) g(i)

‎src/test/regress/sql/polymorphism.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,13 @@ create aggregate build_group(int8, integer) (
427427
STYPE= int8[]
428428
);
429429

430+
-- check that we can apply functions taking ANYARRAY to pg_stats
431+
select distinct array_ndims(histogram_bounds)from pg_stats
432+
where histogram_boundsis not null;
433+
434+
-- such functions must protect themselves if varying element type isn't OK
435+
selectmax(histogram_bounds)from pg_stats;
436+
430437
-- test variadic polymorphic functions
431438

432439
createfunctionmyleast(variadic anyarray) returns anyelementas $$

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp