<entry><literal>array_cat(ARRAY[1,2,3], ARRAY[4,5])</literal></entry>
<entry><literal>{1,2,3,4,5}</literal></entry>
</row>
+ <row>
+ <entry>
+ <literal>
+ <function>array_ndims</function>(<type>anyarray</type>)
+ </literal>
+ </entry>
+ <entry><type>int</type></entry>
+ <entry>returns the number of dimensions of the array</entry>
+ <entry><literal>array_ndims(ARRAY[[1,2,3], [4,5,6]])</literal></entry>
+ <entry><literal>2</literal></entry>
+ </row>
<row>
<entry>
<literal>
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
}
+/*
+ * array_ndims :
+ * returns the number of dimensions of the array pointed to by "v"
+ */
+Datum
+array_ndims(PG_FUNCTION_ARGS)
+{
+ ArrayType *v = PG_GETARG_ARRAYTYPE_P(0);
+
+ /* Sanity check: does it look like an array at all? */
+ if (ARR_NDIM(v) <= 0 || ARR_NDIM(v) > MAXDIM)
+ PG_RETURN_NULL();
+
+ PG_RETURN_INT32(ARR_NDIM(v));
+}
+
/*
* array_dims :
* returns the dimensions of the array pointed to by "v", as a "text"
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 200811031
+#define CATALOG_VERSION_NO 200811041
#endif
DESCR("array less than or equal");
DATA(insert OID = 396 ( array_ge PGNSP PGUID 12 1 0 0 f f t f i 2 16 "2277 2277" _null_ _null_ _null_ array_ge _null_ _null_ _null_ ));
DESCR("array greater than or equal");
+DATA(insert OID = 748 ( array_ndims PGNSP PGUID 12 1 0 0 f f t f i 1 23 "2277" _null_ _null_ _null_ array_ndims _null_ _null_ _null_ ));
DATA(insert OID = 747 ( array_dims PGNSP PGUID 12 1 0 0 f f t f i 1 25 "2277" _null_ _null_ _null_ array_dims _null_ _null_ _null_ ));
DESCR("array dimensions");
DATA(insert OID = 750 ( array_in PGNSP PGUID 12 1 0 0 f f t f s 3 2277 "2275 26 23" _null_ _null_ _null_ array_in _null_ _null_ _null_ ));
extern Datum arrayoverlap(PG_FUNCTION_ARGS);
extern Datum arraycontains(PG_FUNCTION_ARGS);
extern Datum arraycontained(PG_FUNCTION_ARGS);
+extern Datum array_ndims(PG_FUNCTION_ARGS);
extern Datum array_dims(PG_FUNCTION_ARGS);
extern Datum array_lower(PG_FUNCTION_ARGS);
extern Datum array_upper(PG_FUNCTION_ARGS);
{} | {} | {foo,bar} | {}
(3 rows)
+SELECT array_ndims(a) AS a,array_ndims(b) AS b,array_ndims(c) AS c
+ FROM arrtest;
+ a | b | c
+---+---+---
+ 1 | 3 |
+ 1 | 2 | 1
+ | 1 | 1
+(3 rows)
+
SELECT array_dims(a) AS a,array_dims(b) AS b,array_dims(c) AS c
FROM arrtest;
a | b | c
d[1:1][1:2]
FROM arrtest;
+SELECT array_ndims(a) AS a,array_ndims(b) AS b,array_ndims(c) AS c
+ FROM arrtest;
+
SELECT array_dims(a) AS a,array_dims(b) AS b,array_dims(c) AS c
FROM arrtest;