Re: Array Parameters in EXECUTE

Поиск
Список
Период
Сортировка
От Sim Zacks
Тема Re: Array Parameters in EXECUTE
Дата
Msg-id h0rfti$1dgh$1@news.hub.org
обсуждение исходный текст
Ответ на Re: Array Parameters in EXECUTE  ("Shakil Shaikh" <sshaikh@hotmail.com>)
Список pgsql-general
You get what you ask for :-)
You can use the function array-to-string with a comma as the separator.
The array should look like '{val1,val2,val3}' in text format.

Sim

Shakil Shaikh wrote:
> Re added list!
>
> --------------------------------------------------
> Sent: Thursday, June 11, 2009 11:04 AM
> To: "Shakil Shaikh" <>
> Subject: Re: [GENERAL] Array Parameters in EXECUTE
>
>>> Here's my general situation: I have a function which takes in an
>>> optional ARRAY of Ids as so:
>>>
>>> RETURN QUERY SELECT * FROM a WHERE a.id = ANY(v_ids) or v_ids is null;
>>>
>>> However it seems that the ...or v_ids is null... bit forces a sequential
>>
>>
>> If I understand what you are trying to do, if your passed in parameter
>> is null then select * and if there is something there then check it.
>> I would put the statement in an if:
>>
>> if v_ids is null then
>> RETURN QUERY select * from a;
>> else
>> return query SELECT * FROM a WHERE a.id = ANY(v_ids)
>> end if;
>>
>
> This works fine for the trivial case given but not for when there are
> multiple optional array parameters (I know, I know...). I will probably
> use branching for one or two parameters, but for three or four it might
> get a bit cumbersome so I was wondering if there was a more general
> solution.
>
> Shak
>

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

Предыдущее
От: Eric Schwarzenbach
Дата:
Сообщение: Re: When to use cascading deletes?
Следующее
От: Josh Berkus
Дата:
Сообщение: Re: [sfpug] "Rails and PostgreSQL" now up on media.postgresql.org