1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-19 17:02:53 +03:00

array_length() function, and for SQL compatibility also cardinality()

function as a special case.

This version still has the suspicious behavior of returning null for an
empty array (rather than zero), but this may need a wholesale revision of
empty array behavior, currently under discussion.

Jim Nasby, Robert Haas, Peter Eisentraut
This commit is contained in:
Peter Eisentraut
2008-11-12 13:09:28 +00:00
parent 4c22564471
commit f98f6ee064
8 changed files with 135 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.456 2008/11/07 22:54:41 tgl Exp $ -->
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.457 2008/11/12 13:09:27 petere Exp $ -->
<chapter id="functions">
<title>Functions and Operators</title>
@@ -9408,6 +9408,17 @@ SELECT NULLIF(value, '(none)') ...
<entry><literal>array_fill(7, ARRAY[3], ARRAY[2])</literal></entry>
<entry><literal>[2:4]={7,7,7}</literal></entry>
</row>
<row>
<entry>
<literal>
<function>array_length</function>(<type>anyarray</type>, <type>int</type>)
</literal>
</entry>
<entry><type>int</type></entry>
<entry>returns the length of the requested array dimension</entry>
<entry><literal>array_length(array[1,2,3], 1)</literal></entry>
<entry><literal>3</literal></entry>
</row>
<row>
<entry>
<literal>
@@ -9452,6 +9463,19 @@ SELECT NULLIF(value, '(none)') ...
<entry><literal>array_upper(ARRAY[1,2,3,4], 1)</literal></entry>
<entry><literal>4</literal></entry>
</row>
<row>
<entry>
<literal>
<function>cardinality</function>(<type>anyarray</type>)
</literal>
</entry>
<entry><type>int</type></entry>
<entry>returns the length of the first dimension of the array
(special case of <function>array_length</function> for SQL
compatibility)</entry>
<entry><literal>cardinality(array[1,2,3])</literal></entry>
<entry><literal>3</literal></entry>
</row>
<row>
<entry>
<literal>