diff options
| author | Robert Haas | 2014-01-21 17:38:53 +0000 |
|---|---|---|
| committer | Robert Haas | 2014-01-21 17:38:53 +0000 |
| commit | 01f7808b3eafcae1f6077f2f61e13b4c132ccd47 (patch) | |
| tree | 744e328b7dddbdd7294e341f6165d58e51024cdd /src/test | |
| parent | 033b2343fae9d8c9df124cde62087dcb481c9c5e (diff) | |
Add a cardinality function for arrays.
Unlike our other array functions, this considers the total number of
elements across all dimensions, and returns 0 rather than NULL when the
array has no elements. But it seems that both of those behaviors are
almost universally disliked, so hopefully that's OK.
Marko Tiikkaja, reviewed by Dean Rasheed and Pavel Stehule
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/arrays.out | 42 | ||||
| -rw-r--r-- | src/test/regress/sql/arrays.sql | 8 |
2 files changed, 50 insertions, 0 deletions
diff --git a/src/test/regress/expected/arrays.out b/src/test/regress/expected/arrays.out index 23b3902017b..e1b9d7f0a84 100644 --- a/src/test/regress/expected/arrays.out +++ b/src/test/regress/expected/arrays.out @@ -1455,6 +1455,48 @@ select array_length(array[[1,2,3], [4,5,6]], 3); (1 row) +select cardinality(NULL::int[]); + cardinality +------------- + +(1 row) + +select cardinality('{}'::int[]); + cardinality +------------- + 0 +(1 row) + +select cardinality(array[1,2,3]); + cardinality +------------- + 3 +(1 row) + +select cardinality('[2:4]={5,6,7}'::int[]); + cardinality +------------- + 3 +(1 row) + +select cardinality('{{1,2}}'::int[]); + cardinality +------------- + 2 +(1 row) + +select cardinality('{{1,2},{3,4},{5,6}}'::int[]); + cardinality +------------- + 6 +(1 row) + +select cardinality('{{{1}},{{2,3},{3,4}}}'::int[]); + cardinality +------------- + 8 +(1 row) + select array_agg(unique1) from (select unique1 from tenk1 where unique1 < 15 order by unique1) ss; array_agg -------------------------------------- diff --git a/src/test/regress/sql/arrays.sql b/src/test/regress/sql/arrays.sql index e4f9f316ce4..64630d9ab78 100644 --- a/src/test/regress/sql/arrays.sql +++ b/src/test/regress/sql/arrays.sql @@ -419,6 +419,14 @@ select array_length(array[[1,2,3], [4,5,6]], 1); select array_length(array[[1,2,3], [4,5,6]], 2); select array_length(array[[1,2,3], [4,5,6]], 3); +select cardinality(NULL::int[]); +select cardinality('{}'::int[]); +select cardinality(array[1,2,3]); +select cardinality('[2:4]={5,6,7}'::int[]); +select cardinality('{{1,2}}'::int[]); +select cardinality('{{1,2},{3,4},{5,6}}'::int[]); +select cardinality('{{{1}},{{2,3},{3,4}}}'::int[]); + select array_agg(unique1) from (select unique1 from tenk1 where unique1 < 15 order by unique1) ss; select array_agg(ten) from (select ten from tenk1 where unique1 < 15 order by unique1) ss; select array_agg(nullif(ten, 4)) from (select ten from tenk1 where unique1 < 15 order by unique1) ss; |
