]> granicus.if.org Git - postgresql/commitdiff
Make array_cat more paranoid about checking datatypes in empty arrays.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 17 Dec 2004 21:00:07 +0000 (21:00 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 17 Dec 2004 21:00:07 +0000 (21:00 +0000)
src/backend/utils/adt/array_userfuncs.c

index 2397a2b2cfd36d9cdca873d3f69e869601386061..cdd4b7b16a6850e6ebfd5c199d7a33bd126a9687 100644 (file)
@@ -6,7 +6,7 @@
  * Copyright (c) 2003, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/utils/adt/array_userfuncs.c,v 1.11 2003/09/25 06:58:03 petere Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/utils/adt/array_userfuncs.c,v 1.11.2.1 2004/12/17 21:00:07 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -165,6 +165,22 @@ array_cat(PG_FUNCTION_ARGS)
        v1 = PG_GETARG_ARRAYTYPE_P(0);
        v2 = PG_GETARG_ARRAYTYPE_P(1);
 
+       element_type1 = ARR_ELEMTYPE(v1);
+       element_type2 = ARR_ELEMTYPE(v2);
+
+       /* Check we have matching element types */
+       if (element_type1 != element_type2)
+               ereport(ERROR,
+                               (errcode(ERRCODE_DATATYPE_MISMATCH),
+                                errmsg("cannot concatenate incompatible arrays"),
+                                errdetail("Arrays with element types %s and %s are not "
+                                                  "compatible for concatenation.",
+                                                  format_type_be(element_type1),
+                                                  format_type_be(element_type2))));
+
+       /* OK, use it */
+       element_type = element_type1;
+
        /*----------
         * We must have one of the following combinations of inputs:
         * 1) one empty array, and one non-empty array
@@ -200,22 +216,6 @@ array_cat(PG_FUNCTION_ARGS)
                                                   "compatible for concatenation.",
                                                   ndims1, ndims2)));
 
-       element_type1 = ARR_ELEMTYPE(v1);
-       element_type2 = ARR_ELEMTYPE(v2);
-
-       /* Check we have matching element types */
-       if (element_type1 != element_type2)
-               ereport(ERROR,
-                               (errcode(ERRCODE_DATATYPE_MISMATCH),
-                                errmsg("cannot concatenate incompatible arrays"),
-                                errdetail("Arrays with element types %s and %s are not "
-                                                  "compatible for concatenation.",
-                                                  format_type_be(element_type1),
-                                                  format_type_be(element_type2))));
-
-       /* OK, use it */
-       element_type = element_type1;
-
        /* get argument array details */
        lbs1 = ARR_LBOUND(v1);
        lbs2 = ARR_LBOUND(v2);