8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.108 2003/08/04 02:40:01 momjian Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.109 2003/09/23 17:12:53 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -762,6 +762,12 @@ coerce_to_common_type(ParseState *pstate, Node *node,
762
762
* If we have UNKNOWN input (ie, an untyped literal) for any ANYELEMENT
763
763
* or ANYARRAY argument, assume it is okay.
764
764
*
765
+ * If an input is of type ANYARRAY (ie, we know it's an array, but not
766
+ * what element type), we will accept it as a match to an argument declared
767
+ * ANYARRAY, so long as we don't have to determine an element type ---
768
+ * that is, so long as there is no use of ANYELEMENT. This is mostly for
769
+ * backwards compatibility with the pre-7.4 behavior of ANYARRAY.
770
+ *
765
771
* We do not ereport here, but just return FALSE if a rule is violated.
766
772
*/
767
773
bool
@@ -773,6 +779,7 @@ check_generic_type_consistency(Oid *actual_arg_types,
773
779
Oid elem_typeid = InvalidOid ;
774
780
Oid array_typeid = InvalidOid ;
775
781
Oid array_typelem ;
782
+ bool have_anyelement = false;
776
783
777
784
/*
778
785
* Loop through the arguments to see if we have any that are ANYARRAY
@@ -785,6 +792,7 @@ check_generic_type_consistency(Oid *actual_arg_types,
785
792
786
793
if (declared_arg_types [j ] == ANYELEMENTOID )
787
794
{
795
+ have_anyelement = true;
788
796
if (actual_type == UNKNOWNOID )
789
797
continue ;
790
798
if (OidIsValid (elem_typeid ) && actual_type != elem_typeid )
@@ -804,6 +812,14 @@ check_generic_type_consistency(Oid *actual_arg_types,
804
812
/* Get the element type based on the array type, if we have one */
805
813
if (OidIsValid (array_typeid ))
806
814
{
815
+ if (array_typeid == ANYARRAYOID )
816
+ {
817
+ /* Special case for ANYARRAY input: okay iff no ANYELEMENT */
818
+ if (have_anyelement )
819
+ return false;
820
+ return true;
821
+ }
822
+
807
823
array_typelem = get_element_type (array_typeid );
808
824
if (!OidIsValid (array_typelem ))
809
825
return false; /* should be an array, but isn't */
@@ -875,7 +891,8 @@ enforce_generic_type_consistency(Oid *actual_arg_types,
875
891
bool have_unknowns = false;
876
892
Oid elem_typeid = InvalidOid ;
877
893
Oid array_typeid = InvalidOid ;
878
- Oid array_typelem = InvalidOid ;
894
+ Oid array_typelem ;
895
+ bool have_anyelement = (rettype == ANYELEMENTOID );
879
896
880
897
/*
881
898
* Loop through the arguments to see if we have any that are ANYARRAY
@@ -888,7 +905,7 @@ enforce_generic_type_consistency(Oid *actual_arg_types,
888
905
889
906
if (declared_arg_types [j ] == ANYELEMENTOID )
890
907
{
891
- have_generics = true;
908
+ have_generics = have_anyelement = true;
892
909
if (actual_type == UNKNOWNOID )
893
910
{
894
911
have_unknowns = true;
@@ -932,12 +949,20 @@ enforce_generic_type_consistency(Oid *actual_arg_types,
932
949
/* Get the element type based on the array type, if we have one */
933
950
if (OidIsValid (array_typeid ))
934
951
{
935
- array_typelem = get_element_type (array_typeid );
936
- if (!OidIsValid (array_typelem ))
937
- ereport (ERROR ,
938
- (errcode (ERRCODE_DATATYPE_MISMATCH ),
939
- errmsg ("argument declared ANYARRAY is not an array but %s" ,
940
- format_type_be (array_typeid ))));
952
+ if (array_typeid == ANYARRAYOID && !have_anyelement )
953
+ {
954
+ /* Special case for ANYARRAY input: okay iff no ANYELEMENT */
955
+ array_typelem = InvalidOid ;
956
+ }
957
+ else
958
+ {
959
+ array_typelem = get_element_type (array_typeid );
960
+ if (!OidIsValid (array_typelem ))
961
+ ereport (ERROR ,
962
+ (errcode (ERRCODE_DATATYPE_MISMATCH ),
963
+ errmsg ("argument declared ANYARRAY is not an array but %s" ,
964
+ format_type_be (array_typeid ))));
965
+ }
941
966
942
967
if (!OidIsValid (elem_typeid ))
943
968
{
0 commit comments