Re: Array Parameters in EXECUTE

From: Sim Zacks <sim(at)compulab(dot)co(dot)il>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Array Parameters in EXECUTE
Date: 2009-06-11 11:16:56
Message-ID: h0qp38$gq9$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Sim Zacks 2009-06-11 11:19:16 Re: When to use cascading deletes?
Previous Message Greg Stark 2009-06-11 11:10:47 Re: queries on xmin