Search Postgresql Archives

Re: Array Parameters in EXECUTE

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 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


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux