From 6efbded6e4672c597a6f0dc0f09263e7db7369ff Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 22 Dec 2015 21:05:16 -0500 Subject: Allow omitting one or both boundaries in an array slice specifier. Omitted boundaries represent the upper or lower limit of the corresponding array subscript. This allows simpler specification of many common use-cases. (Revised version of commit 9246af6799819847faa33baf441251003acbb8fe) YUriy Zhuravlev --- doc/src/sgml/array.sgml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'doc/src') diff --git a/doc/src/sgml/array.sgml b/doc/src/sgml/array.sgml index 4385a09cd97..58878451f00 100644 --- a/doc/src/sgml/array.sgml +++ b/doc/src/sgml/array.sgml @@ -276,6 +276,29 @@ SELECT schedule[1:2][2] FROM sal_emp WHERE name = 'Bill'; for all dimensions, e.g., [1:2][1:1], not [2][1:1]. + + It is possible to omit the lower-bound and/or + upper-bound of a slice specifier; the missing + bound is replaced by the lower or upper limit of the array's subscripts. + For example: + + +SELECT schedule[:2][2:] FROM sal_emp WHERE name = 'Bill'; + + schedule +------------------------ + {{lunch},{presentation}} +(1 row) + +SELECT schedule[:][1:1] FROM sal_emp WHERE name = 'Bill'; + + schedule +------------------------ + {{meeting},{training}} +(1 row) + + + An array subscript expression will return null if either the array itself or any of the subscript expressions are null. Also, null is returned if a @@ -391,6 +414,10 @@ UPDATE sal_emp SET pay_by_quarter[1:2] = '{27000,27000}' WHERE name = 'Carol'; + The slice syntaxes with omitted lower-bound and/or + upper-bound can be used too, but only when + updating an array value that is not NULL or zero-dimensional (otherwise, + there is no existing subscript limit to substitute). -- cgit v1.2.3