From: | Steve Crawford <scrawford(at)pinpointresearch(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | string_to_array with empty input |
Date: | 2009-03-30 18:55:53 |
Message-ID: | 49D115B9.7030801@pinpointresearch.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-hackers |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Andrej | 2009-03-30 19:03:06 | Re: [GENEAL] dynamically changing table |
Previous Message | A B | 2009-03-30 18:50:59 | Re: [GENEAL] dynamically changing table |
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew Chernow | 2009-03-30 18:56:04 | Re: PQinitSSL broken in some use casesf |
Previous Message | Robert Haas | 2009-03-30 18:45:56 | Re: PQinitSSL broken in some use casesf |