From 97690ea6e86c412461dd5dc99953b829564d1a55 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Mon, 30 Mar 2015 16:13:21 -0300 Subject: Change array_offset to return subscripts, not offsets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... and rename it and its sibling array_offsets to array_position and array_positions, to account for the changed behavior. Having the functions return subscripts better matches existing practice, and is better suited to using the result value as a subscript into the array directly. For one-based arrays, the new definition is identical to what was originally committed. (We use the term "subscript" in the documentation, which is what we use whenever we talk about arrays; but the functions themselves are named using the word "position" to match the standard-defined POSITION() functions.) Author: Pavel Stěhule Behavioral problem noted by Dean Rasheed. --- doc/src/sgml/array.sgml | 18 +++++++++--------- doc/src/sgml/func.sgml | 22 +++++++++++----------- 2 files changed, 20 insertions(+), 20 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/array.sgml b/doc/src/sgml/array.sgml index 092013b83b5..5e4130aa6df 100644 --- a/doc/src/sgml/array.sgml +++ b/doc/src/sgml/array.sgml @@ -601,20 +601,20 @@ SELECT * FROM sal_emp WHERE pay_by_quarter && ARRAY[10000]; - You can also search for specific values in an array using the array_offset - and array_offsets functions. The former returns the position of + You can also search for specific values in an array using the array_position + and array_positions functions. The former returns the subscript 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: + subscripts of all occurrences of the value in the array. For example: -SELECT array_offset(ARRAY['sun','mon','tue','wed','thu','fri','sat'], 'mon'); - array_offset --------------- +SELECT array_position(ARRAY['sun','mon','tue','wed','thu','fri','sat'], 'mon'); + array_positions +----------------- 2 -SELECT array_offsets(ARRAY[1, 4, 3, 1, 3, 4, 2, 1], 1); - array_offsets ---------------- +SELECT array_positions(ARRAY[1, 4, 3, 1, 3, 4, 2, 1], 1); + array_positions +----------------- {1,4,8} diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 3195655d111..53f31b51f54 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -11481,10 +11481,10 @@ SELECT NULLIF(value, '(none)') ... array_lower - array_offset + array_position - array_offsets + array_positions array_prepend @@ -11606,27 +11606,27 @@ SELECT NULLIF(value, '(none)') ... - array_offset(anyarray, anyelement , int) + array_position(anyarray, anyelement , int) int - returns the offset of the first occurrence of the second + returns the subscript of the first occurrence of the second argument in the array, starting at the element indicated by the third argument or at the first element (array must be one-dimensional) - array_offset(ARRAY['sun','mon','tue','wed','thu','fri','sat'], 'mon') + array_position(ARRAY['sun','mon','tue','wed','thu','fri','sat'], 'mon') 2 - array_offsets(anyarray, anyelement) + array_positions(anyarray, anyelement) int[] - returns an array of offsets of all occurrences of the second + returns an array of subscripts of all occurrences of the second argument in the array given as first argument (array must be one-dimensional) - array_offsets(ARRAY['A','A','B','A'], 'A') + array_positions(ARRAY['A','A','B','A'], 'A') {1,2,4} @@ -11741,18 +11741,18 @@ NULL baz(3 rows) - In array_offset and array_offsets, + In array_position and array_positions, each array element is compared to the searched value using IS NOT DISTINCT FROM semantics. - In array_offset, NULL is returned + In array_position, NULL is returned if the value is not found. - In array_offsets, NULL is returned + In array_positions, NULL is returned only if the array is NULL; if the value is not found in the array, an empty array is returned instead. -- cgit v1.2.3