]> granicus.if.org Git - postgresql/commitdiff
Allow zero-dimensional (ie, empty) arrays in contrib/ltree operations.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 24 Feb 2010 18:02:30 +0000 (18:02 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 24 Feb 2010 18:02:30 +0000 (18:02 +0000)
The main motivation for changing this is bug #4921, in which it's pointed out
that it's no longer safe to apply ltree operations to the result of
ARRAY(SELECT ...) if the sub-select might return no rows.  Before 8.3,
the ARRAY() construct would return NULL, which might or might not be helpful
but at least it wouldn't result in an error.  Now it returns an empty array
which results in a failure for no good reason, since the ltree operations
are all perfectly capable of dealing with zero-element arrays.

As far as I can find, these ltree functions are the only places where zero
array dimensionality is rejected unnecessarily.

Back-patch to 8.3 to prevent behavioral regression of queries that worked
in older releases.

contrib/ltree/_ltree_gist.c
contrib/ltree/_ltree_op.c
contrib/ltree/lquery_op.c
contrib/ltree/ltree_gist.c

index 15c4cc022d77ca9ad3b1f8a62ef7f55556a1cdd8..933e85f17f446d517d6e564df7d91f2a66cf61aa 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $PostgreSQL: pgsql/contrib/ltree/_ltree_gist.c,v 1.26 2009/06/11 14:48:51 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/ltree/_ltree_gist.c,v 1.26.2.1 2010/02/24 18:02:30 tgl Exp $
  *
  *
  * GiST support for ltree[]
@@ -88,7 +88,7 @@ _ltree_compress(PG_FUNCTION_ARGS)
                int                     num = ArrayGetNItems(ARR_NDIM(val), ARR_DIMS(val));
                ltree      *item = (ltree *) ARR_DATA_PTR(val);
 
-               if (ARR_NDIM(val) != 1)
+               if (ARR_NDIM(val) > 1)
                        ereport(ERROR,
                                        (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
                                         errmsg("array must be one-dimensional")));
@@ -534,7 +534,7 @@ _arrq_cons(ltree_gist *key, ArrayType *_query)
        lquery     *query = (lquery *) ARR_DATA_PTR(_query);
        int                     num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
 
-       if (ARR_NDIM(_query) != 1)
+       if (ARR_NDIM(_query) > 1)
                ereport(ERROR,
                                (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
                                 errmsg("array must be one-dimensional")));
index f9e90e978dd962956924fa9d5d992c063cbaee10..ca8032eb7eb040b5aa1517f675e53562942f30c1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $PostgreSQL: pgsql/contrib/ltree/_ltree_op.c,v 1.13 2009/06/11 14:48:51 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/ltree/_ltree_op.c,v 1.13.2.1 2010/02/24 18:02:30 tgl Exp $
  *
  *
  * op function for ltree[]
@@ -48,7 +48,7 @@ array_iterator(ArrayType *la, PGCALL2 callback, void *param, ltree **found)
        int                     num = ArrayGetNItems(ARR_NDIM(la), ARR_DIMS(la));
        ltree      *item = (ltree *) ARR_DATA_PTR(la);
 
-       if (ARR_NDIM(la) != 1)
+       if (ARR_NDIM(la) > 1)
                ereport(ERROR,
                                (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
                                 errmsg("array must be one-dimensional")));
@@ -148,7 +148,7 @@ _lt_q_regex(PG_FUNCTION_ARGS)
        bool            res = false;
        int                     num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
 
-       if (ARR_NDIM(_query) != 1)
+       if (ARR_NDIM(_query) > 1)
                ereport(ERROR,
                                (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
                                 errmsg("array must be one-dimensional")));
@@ -306,7 +306,7 @@ _lca(PG_FUNCTION_ARGS)
        ltree     **a,
                           *res;
 
-       if (ARR_NDIM(la) != 1)
+       if (ARR_NDIM(la) > 1)
                ereport(ERROR,
                                (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
                                 errmsg("array must be one-dimensional")));
index df4f0794f2be4a5a01520af92718d024821421ab..f22a508a4192a6c93b4ccdd3f6533b2899ef5fce 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * op function for ltree and lquery
  * Teodor Sigaev <teodor@stack.net>
- * $PostgreSQL: pgsql/contrib/ltree/lquery_op.c,v 1.14 2009/06/11 14:48:51 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/ltree/lquery_op.c,v 1.14.2.1 2010/02/24 18:02:30 tgl Exp $
  */
 #include "postgres.h"
 
@@ -344,7 +344,7 @@ lt_q_regex(PG_FUNCTION_ARGS)
        bool            res = false;
        int                     num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
 
-       if (ARR_NDIM(_query) != 1)
+       if (ARR_NDIM(_query) > 1)
                ereport(ERROR,
                                (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
                                 errmsg("array must be one-dimensional")));
index d48ca8e1d4ee387a81cc70e987cee0476876269a..18516831d1a1caeeff6ca202bcdb62c0181439f3 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * GiST support for ltree
  * Teodor Sigaev <teodor@stack.net>
- * $PostgreSQL: pgsql/contrib/ltree/ltree_gist.c,v 1.25 2009/06/11 14:48:51 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/ltree/ltree_gist.c,v 1.25.2.1 2010/02/24 18:02:30 tgl Exp $
  */
 #include "postgres.h"
 
@@ -602,7 +602,7 @@ arrq_cons(ltree_gist *key, ArrayType *_query)
        lquery     *query = (lquery *) ARR_DATA_PTR(_query);
        int                     num = ArrayGetNItems(ARR_NDIM(_query), ARR_DIMS(_query));
 
-       if (ARR_NDIM(_query) != 1)
+       if (ARR_NDIM(_query) > 1)
                ereport(ERROR,
                                (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
                                 errmsg("array must be one-dimensional")));