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 */
14281437Oid
14291438enforce_generic_type_consistency (Oid * actual_arg_types ,
@@ -1438,6 +1447,9 @@ enforce_generic_type_consistency(Oid *actual_arg_types,
14381447 Oid elem_typeid = InvalidOid ;
14391448 Oid array_typeid = InvalidOid ;
14401449 Oid array_typelem ;
1450+ bool have_anyelement = (rettype == ANYELEMENTOID ||
1451+ rettype == ANYNONARRAYOID ||
1452+ rettype == ANYENUMOID );
14411453 bool have_anynonarray = (rettype == ANYNONARRAYOID );
14421454 bool have_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 else if (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 {
0 commit comments