diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2008-11-12 13:09:28 +0000 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2008-11-12 13:09:28 +0000 |
commit | f98f6ee0641e87c6ecc2524f5d0a8b54924ffd14 (patch) | |
tree | a192c5bf9cfea3c4581f16f19ec7f6e8245f3c2a /doc/src | |
parent | 4c22564471e2724bcc62bc2c61ece796c946f16e (diff) | |
download | postgresql-f98f6ee0641e87c6ecc2524f5d0a8b54924ffd14.tar.gz postgresql-f98f6ee0641e87c6ecc2524f5d0a8b54924ffd14.zip |
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
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/array.sgml | 14 | ||||
-rw-r--r-- | doc/src/sgml/func.sgml | 26 |
2 files changed, 38 insertions, 2 deletions
diff --git a/doc/src/sgml/array.sgml b/doc/src/sgml/array.sgml index 4d762c53d35..08a3ee021d2 100644 --- a/doc/src/sgml/array.sgml +++ b/doc/src/sgml/array.sgml @@ -1,4 +1,4 @@ -<!-- $PostgreSQL: pgsql/doc/src/sgml/array.sgml,v 1.67 2008/10/29 11:24:52 petere Exp $ --> +<!-- $PostgreSQL: pgsql/doc/src/sgml/array.sgml,v 1.68 2008/11/12 13:09:27 petere Exp $ --> <sect1 id="arrays"> <title>Arrays</title> @@ -325,6 +325,18 @@ SELECT array_upper(schedule, 1) FROM sal_emp WHERE name = 'Carol'; 2 (1 row) </programlisting> + + <function>array_length</function> will return the length of a specified + array dimension: + +<programlisting> +SELECT array_length(schedule, 1) FROM sal_emp WHERE name = 'Carol'; + + array_length +-------------- + 2 +(1 row) +</programlisting> </para> </sect2> diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 1e329904512..85403e2c9f7 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -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> @@ -9411,6 +9411,17 @@ SELECT NULLIF(value, '(none)') ... <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> <function>array_lower</function>(<type>anyarray</type>, <type>int</type>) </literal> </entry> @@ -9455,6 +9466,19 @@ SELECT NULLIF(value, '(none)') ... <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> <function>string_to_array</function>(<type>text</type>, <type>text</type>) </literal> </entry> |