mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
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
This commit is contained in:
@ -337,6 +337,19 @@ SELECT array_length(schedule, 1) FROM sal_emp WHERE name = 'Carol';
|
||||
--------------
|
||||
2
|
||||
(1 row)
|
||||
</programlisting>
|
||||
|
||||
<function>cardinality</function> returns the total number of elements in an
|
||||
array across all dimensions. It is effectively the number of rows a call to
|
||||
<function>unnest</function> would yield:
|
||||
|
||||
<programlisting>
|
||||
SELECT cardinality(schedule) FROM sal_emp WHERE name = 'Carol';
|
||||
|
||||
cardinality
|
||||
-------------
|
||||
4
|
||||
(1 row)
|
||||
</programlisting>
|
||||
</para>
|
||||
</sect2>
|
||||
|
Reference in New Issue
Block a user