Re: BUG #4509: array_cat's null behaviour is inconsistent - Mailing list pgsql-bugs

From Kev
Subject Re: BUG #4509: array_cat's null behaviour is inconsistent
Date
Msg-id 5aa36b5a-3707-4901-a86f-5c32f5cb7bcd@v22g2000pro.googlegroups.com
Whole thread Raw
In response to BUG #4509: array_cat's null behaviour is inconsistent  ("Kevin Field" <kev@brantaero.com>)
Responses Re: BUG #4509: array_cat's null behaviour is inconsistent
List pgsql-bugs
> I'm loath to change just this one thing though.  If we're going to
> monkey with it, I think we should start by having a thought-through
> proposal about the behavior of all the array functions for corner
> cases like null arrays and empty arrays (cf recent discussion about
> zero-dimensional arrays).

If those are the only corner cases, here's something to work with.

Looking at http://www.postgresql.org/docs/8.3/interactive/functions-array.html,
I'd propose that every one of those operators and functions should
return NULL::(normal-return-type) if any of their operands are NULL,
to be consistent with Section 9.2 and to differentiate from the empty-
array cases below, and that logic should precede anything to do with
empty arrays.  As for empty arrays, the following additions to the
logic:

= true if both arrays are empty
<> true if either array is empty but not both
< true if left operand is empty and right is not
> true if right operand is empty and left is not
<= true if left operand is empty
>= true if right operand is empty
@> true if right operand is empty
<@ true if left operand is empty
&& false if either array is empty
|| (both array-array cases) return other array if one is empty (if
left is empty, return right, elsif right is empty, return left)
|| (both element-array cases) return ARRAY[element] if array is empty

array_append return ARRAY[element] if array is empty
array_cat return other array if one is empty (if left is empty, return
right, elsif right is empty, return left)
array_dims return results obtained by ignoring empty sub-arrays; if
entire array is empty, return ''
array_lower raise exception if array is empty (there are no dimensions
to inquire about)
array_prepend return ARRAY[element] if array is empty
array_to_string return '' if array is empty
array_upper raise exception if array is empty (there are no dimensions
to inquire about)
string_to_array return '' if left operand is ''

Hope that's useful...
Kev

pgsql-bugs by date:

Previous
From: "Alex Hunsaker"
Date:
Subject: Re: plperl & sort
Next
From: "Alexey Bashtanov"
Date:
Subject: BUG #4513: VACUUM FULL fails with "out of memory" error