Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit254aecb

Browse files
committed
ADD array_ndims function
Author: Robert Haas <robertmhaas@gmail.com>
1 parent9beb9e7 commit254aecb

File tree

7 files changed

+47
-6
lines changed

7 files changed

+47
-6
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.454 2008/11/0400:59:45 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.455 2008/11/0414:49:11 petere Exp $ -->
22

33
<chapter id="functions">
44
<title>Functions and Operators</title>
@@ -9373,6 +9373,17 @@ SELECT NULLIF(value, '(none)') ...
93739373
<entry><literal>array_cat(ARRAY[1,2,3], ARRAY[4,5])</literal></entry>
93749374
<entry><literal>{1,2,3,4,5}</literal></entry>
93759375
</row>
9376+
<row>
9377+
<entry>
9378+
<literal>
9379+
<function>array_ndims</function>(<type>anyarray</type>)
9380+
</literal>
9381+
</entry>
9382+
<entry><type>int</type></entry>
9383+
<entry>returns the number of dimensions of the array</entry>
9384+
<entry><literal>array_ndims(ARRAY[[1,2,3], [4,5,6]])</literal></entry>
9385+
<entry><literal>2</literal></entry>
9386+
</row>
93769387
<row>
93779388
<entry>
93789389
<literal>

‎src/backend/utils/adt/arrayfuncs.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.147 2008/07/21 04:47:00 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.148 2008/11/04 14:49:11 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1530,6 +1530,22 @@ array_send(PG_FUNCTION_ARGS)
15301530
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
15311531
}
15321532

1533+
/*
1534+
* array_ndims :
1535+
* returns the number of dimensions of the array pointed to by "v"
1536+
*/
1537+
Datum
1538+
array_ndims(PG_FUNCTION_ARGS)
1539+
{
1540+
ArrayType*v=PG_GETARG_ARRAYTYPE_P(0);
1541+
1542+
/* Sanity check: does it look like an array at all? */
1543+
if (ARR_NDIM(v) <=0||ARR_NDIM(v)>MAXDIM)
1544+
PG_RETURN_NULL();
1545+
1546+
PG_RETURN_INT32(ARR_NDIM(v));
1547+
}
1548+
15331549
/*
15341550
* array_dims :
15351551
* returns the dimensions of the array pointed to by "v", as a "text"

‎src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.501 2008/11/03 17:51:13 tgl Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.502 2008/11/04 14:49:11 petere Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO200811031
56+
#defineCATALOG_VERSION_NO200811041
5757

5858
#endif

‎src/include/catalog/pg_proc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.523 2008/11/03 21:09:17 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.524 2008/11/04 14:49:11 petere Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -985,6 +985,7 @@ DATA(insert OID = 393 ( array_le PGNSP PGUID 12 1 0 0 f f t f i 2 16 "2277
985985
DESCR("array less than or equal");
986986
DATA(insertOID=396 (array_gePGNSPPGUID12100fftfi216"2277 2277"_null__null__null_array_ge_null__null__null_ ));
987987
DESCR("array greater than or equal");
988+
DATA(insertOID=748 (array_ndimsPGNSPPGUID12100fftfi123"2277"_null__null__null_array_ndims_null__null__null_ ));
988989
DATA(insertOID=747 (array_dimsPGNSPPGUID12100fftfi125"2277"_null__null__null_array_dims_null__null__null_ ));
989990
DESCR("array dimensions");
990991
DATA(insertOID=750 (array_inPGNSPPGUID12100fftfs32277"2275 26 23"_null__null__null_array_in_null__null__null_ ));

‎src/include/utils/array.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
5050
* Portions Copyright (c) 1994, Regents of the University of California
5151
*
52-
* $PostgreSQL: pgsql/src/include/utils/array.h,v 1.68 2008/07/16 00:48:54 momjian Exp $
52+
* $PostgreSQL: pgsql/src/include/utils/array.h,v 1.69 2008/11/04 14:49:12 petere Exp $
5353
*
5454
*-------------------------------------------------------------------------
5555
*/
@@ -195,6 +195,7 @@ extern Datum btarraycmp(PG_FUNCTION_ARGS);
195195
externDatumarrayoverlap(PG_FUNCTION_ARGS);
196196
externDatumarraycontains(PG_FUNCTION_ARGS);
197197
externDatumarraycontained(PG_FUNCTION_ARGS);
198+
externDatumarray_ndims(PG_FUNCTION_ARGS);
198199
externDatumarray_dims(PG_FUNCTION_ARGS);
199200
externDatumarray_lower(PG_FUNCTION_ARGS);
200201
externDatumarray_upper(PG_FUNCTION_ARGS);

‎src/test/regress/expected/arrays.out

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ SELECT a[1:3],
6868
{} | {} | {foo,bar} | {}
6969
(3 rows)
7070

71+
SELECT array_ndims(a) AS a,array_ndims(b) AS b,array_ndims(c) AS c
72+
FROM arrtest;
73+
a | b | c
74+
---+---+---
75+
1 | 3 |
76+
1 | 2 | 1
77+
| 1 | 1
78+
(3 rows)
79+
7180
SELECT array_dims(a) AS a,array_dims(b) AS b,array_dims(c) AS c
7281
FROM arrtest;
7382
a | b | c

‎src/test/regress/sql/arrays.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ SELECT a[1:3],
5353
d[1:1][1:2]
5454
FROM arrtest;
5555

56+
SELECT array_ndims(a)AS a,array_ndims(b)AS b,array_ndims(c)AS c
57+
FROM arrtest;
58+
5659
SELECT array_dims(a)AS a,array_dims(b)AS b,array_dims(c)AS c
5760
FROM arrtest;
5861

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp