mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
array_offset() and array_offsets()
These functions return the offset position or positions of a value in an array. Author: Pavel Stěhule Reviewed by: Jim Nasby
This commit is contained in:
@ -600,6 +600,25 @@ SELECT * FROM sal_emp WHERE pay_by_quarter && ARRAY[10000];
|
||||
index, as described in <xref linkend="indexes-types">.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
You can also search for specific values in an array using the <function>array_offset</>
|
||||
and <function>array_offsets</> functions. The former returns the position of
|
||||
the first occurrence of a value in an array; the latter returns an array with the
|
||||
positions of all occurrences of the value in the array. For example:
|
||||
|
||||
<programlisting>
|
||||
SELECT array_offset(ARRAY['sun','mon','tue','wed','thu','fri','sat'], 'mon');
|
||||
array_offset
|
||||
--------------
|
||||
2
|
||||
|
||||
SELECT array_offsets(ARRAY[1, 4, 3, 1, 3, 4, 2, 1], 1);
|
||||
array_offsets
|
||||
---------------
|
||||
{1,4,8}
|
||||
</programlisting>
|
||||
</para>
|
||||
|
||||
<tip>
|
||||
<para>
|
||||
Arrays are not sets; searching for specific array elements
|
||||
|
Reference in New Issue
Block a user