In plpgsql, don't try to convert int2vector or oidvector to expanded array.
authorTom Lane
Thu, 18 Aug 2016 18:48:51 +0000 (14:48 -0400)
committerTom Lane
Thu, 18 Aug 2016 18:48:51 +0000 (14:48 -0400)
These types are storage-compatible with real arrays, but they don't support
toasting, so of course they can't support expansion either.

Per bug #14289 from Michael Overmeyer.  Back-patch to 9.5 where expanded
arrays were introduced.

Report: <20160818174414[email protected]>

src/include/utils/array.h
src/pl/plpgsql/src/pl_comp.c

index c25b80d272aeb2c1b824f033b72fd8ef3afe28c1..0f934b617383e6a42411dd2f0c64d8d3755b0601 100644 (file)
@@ -36,7 +36,7 @@
  *
  * The OIDVECTOR and INT2VECTOR datatypes are storage-compatible with
  * generic arrays, but they support only one-dimensional arrays with no
- * nulls (and no null bitmap).
+ * nulls (and no null bitmap).  They don't support being toasted, either.
  *
  * There are also some "fixed-length array" datatypes, such as NAME and
  * POINT.  These are simply a sequence of a fixed number of items each
index 0ff20860f3b78f62644ec564b0155195b9036dc1..53c150fa54ce7de2c035909f484c79c02a9f7b6b 100644 (file)
@@ -2204,14 +2204,19 @@ build_datatype(HeapTuple typeTup, int32 typmod, Oid collation)
    /* NB: this is only used to decide whether to apply expand_array */
    if (typeStruct->typtype == TYPTYPE_BASE)
    {
-       /* this test should match what get_element_type() checks */
+       /*
+        * This test should include what get_element_type() checks.  We also
+        * disallow non-toastable array types (i.e. oidvector and int2vector).
+        */
        typ->typisarray = (typeStruct->typlen == -1 &&
-                          OidIsValid(typeStruct->typelem));
+                          OidIsValid(typeStruct->typelem) &&
+                          typeStruct->typstorage != 'p');
    }
    else if (typeStruct->typtype == TYPTYPE_DOMAIN)
    {
        /* we can short-circuit looking up base types if it's not varlena */
        typ->typisarray = (typeStruct->typlen == -1 &&
+                          typeStruct->typstorage != 'p' &&
                 OidIsValid(get_base_element_type(typeStruct->typbasetype)));
    }
    else