From: Sabin Coanda <sabin.coanda@deuromedia.ro>
To: pgsql-sql@postgresql.org
Subject: Re: array_to_string
Date: Mon, 18 Jun 2007 10:17:19 +0300
Message-ID: <f55bhl$2c7p$1@news.hub.org> (raw)
References: <euaelf$28f8$1@news.hub.org>
<20090.1175006990@sss.pgh.pa.us>
"Tom Lane" <tgl@sss.pgh.pa.us> wrote in message
news:20090.1175006990@sss.pgh.pa.us...
> "Sabin Coanda" <sabin.coanda@deuromedia.ro> writes:
>> I used the function array_to_string, and I found it ignores NULL values,
>> e.g. array_to_string( 'ARRAY[1,NULL,3]', ',' ) returns '1,3'.
>
> Do you have a better idea?
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: You can help support the PostgreSQL project by donating at
>
> http://www.postgresql.org/about/donate
>
I found the function would be useful to build dynamic statements that
includes array items.
For instance I have a function with an array argument of integer. In that
function I'd like to send that argument by a dynamic string to other
function. If array_to_string would return the whole elements, including
NULLs, I'd be able to build that statement. But with the present behavior,
the result statement damages the array structure.
On the other hand, I saw there is available its complement function
string_to_array. It would be nice to be able to reverse a string built by
array_to_string, with string_to_array, getting the original array. This
could happen if the function would consider the NULLs as well.
A simple 'NULL' string would be enough to fulfil this reversing process, so
that array_to_string( ARRAY[1,NULL,3], ',' ) would returns '1,NULL,3'.
A problem will occur when it would be applied to string arrays, because NULL
string, and 'NULL' string value would have the same result. This could be
solved if the string arrays would be formed with the same rules as for SQL
constant syntax. I mean with quotes. So that, array_to_string( ARRAY[ 'a',
'NULL', NULL, 'b'], '/' ) would return not a/NULL/NULL/b , but
'a'/'NULL'/NULL/'b'. Consequently, string_to_array function should interpret
this result.
Regards,
Sabin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: sabin.coanda@deuromedia.ro
Subject: Re: array_to_string
In-Reply-To: <f55bhl$2c7p$1@news.hub.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox