In reading our array documentation I came across two unusual behaviors. The issue relates to slices:
We can also access arbitrary rectangular slices of an array, or subarrays. An array slice is denoted by writing <literal><replaceable>lower-bound</replaceable>:<replaceable>upper-bound</replaceable></literal> for one or more array dimensions. For example, this query retrieves the first item on Bill's schedule for the first two days of the week: SELECT schedule[1:2][1:1] FROM sal_emp WHERE name = 'Bill'; First issue: If any dimension is written as a slice, i.e. contains a colon, then all dimensions are treated as slices. Any dimension that has only a single number (no colon) is treated as being from <literal>1</> to the number specified. For example, <literal>[2]</> is treated as <literal>[1:2]</>, as in this example: Is the the behavior of assuming an entry with no colon is a slice what we want, or are we just stuck with it? Also: 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). For example, if <literal>schedule</> currently has the dimensions <literal>[1:3][1:2]</> then referencing <literal>schedule[3][3]</> yields NULL. Similarly, an array reference with the wrong number of subscripts yields a null rather than an error. An array slice expression likewise yields null if the array itself or any of the subscript expressions are null. However, in other corner cases such as selecting an array slice that is completely outside the current array bounds, a slice expression yields an empty (zero-dimensional) array instead of null. If the requested slice partially overlaps the array bounds, then it is silently reduced to just the overlapping region. Is there a reason out-of-bounds array accesses behave differently for slices and non-slices? Having slices and non-slices behave differently is very confusing to me. -- Bruce Momjian <[EMAIL PROTECTED]> http://momjian.us EnterpriseDB http://postgres.enterprisedb.com + If your life is a hard drive, Christ can be your backup. + ---------------------------(end of broadcast)--------------------------- TIP 6: explain analyze is your friend