I have a query that converts a string to an array with the
string_to_array function. Sometimes the input is an empty string (not a
null, but a string of zero-length). I had expected the result to be a
one-element array with an empty string as the first and only element but
instead it returned null. I looked at the docs and didn't find the
observed behavior documented.
I ran some tests:
string_to_array(null,',') -- expected and got null
string_to_array('a',',') -- expected and got one-element array {a}
string_to_array('',',') -- expected consistency with above (one-element
array with empty string) but got null
So I looked to see how array_to_string deals with such arrays:
array_to_string('{""}'::text[],',') -- expected and got an empty string
I realize that array_to_string is not a perfect inverse of
string_to_array - especially due to the fact that the array-index is not
preserved. But it seems that the array data should match.
Is this a bug or am I missing the logic behind this behavior? As it
stands, it appears I will have to wrap the function in a case statement
as a work-around unless there is a better solution.
Cheers,
Steve
--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general