Re: array_to_string

Поиск
Список
Период
Сортировка
От Sabin Coanda
Тема Re: array_to_string
Дата
Msg-id f55bhl$2c7p$1@news.hub.org
обсуждение исходный текст
Ответ на array_to_string  ("Sabin Coanda" <sabin.coanda@deuromedia.ro>)
Список pgsql-sql
"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




В списке pgsql-sql по дате отправления:

Предыдущее
От: Jeff Frost
Дата:
Сообщение: Re: separating improperly grouped page views
Следующее
От: Ranieri Mazili
Дата:
Сообщение: Exec a text variable as select