Re: Array Parameters in EXECUTE - Mailing list pgsql-general

From Sim Zacks
Subject Re: Array Parameters in EXECUTE
Date
Msg-id h0qp38$gq9$1@news.hub.org
Whole thread Raw
In response to Array Parameters in EXECUTE  ("Shakil Shaikh" <sshaikh@hotmail.com>)
List pgsql-general
> 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;
>


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;


It's definitely better then the loop.


Sim


pgsql-general by date:

Previous
From: Steve Clark
Date:
Subject: Re: When to use cascading deletes?
Next
From: Sim Zacks
Date:
Subject: Re: When to use cascading deletes?