diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2015-12-22 21:05:16 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2015-12-22 21:05:29 -0500 |
commit | 6efbded6e4672c597a6f0dc0f09263e7db7369ff (patch) | |
tree | 2ee78e250058cdbc4021f24c6ae0bf4e92098c4b /doc/src | |
parent | 0ba3f3bc65f1176250b942e14fd9e4975a5d3913 (diff) | |
download | postgresql-6efbded6e4672c597a6f0dc0f09263e7db7369ff.tar.gz postgresql-6efbded6e4672c597a6f0dc0f09263e7db7369ff.zip |
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
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/array.sgml | 27 |
1 files changed, 27 insertions, 0 deletions
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 @@ -277,6 +277,29 @@ SELECT schedule[1:2][2] FROM sal_emp WHERE name = 'Bill'; </para> <para> + It is possible to omit the <replaceable>lower-bound</replaceable> and/or + <replaceable>upper-bound</replaceable> of a slice specifier; the missing + bound is replaced by the lower or upper limit of the array's subscripts. + For example: + +<programlisting> +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) +</programlisting> + </para> + + <para> 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 subscript is outside the array bounds (this case does not raise an error). @@ -391,6 +414,10 @@ UPDATE sal_emp SET pay_by_quarter[1:2] = '{27000,27000}' WHERE name = 'Carol'; </programlisting> + The slice syntaxes with omitted <replaceable>lower-bound</replaceable> and/or + <replaceable>upper-bound</replaceable> 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). </para> <para> |