I am trying to simplify the following SQL statement (wrapped into function for clarity).
What is a simpler/natural syntactical way to use array inside where ... in (/*array*/) clause?
(without select * from unnest(...) boilerplate)
CREATE OR REPLACE FUNCTION get_items(p_ids int[])
RETURNS SETOF text
LANGUAGE sql
AS $$
select t.name
from my_table t
where f.id in (select * from unnest(p_ids))
$$;
Don't use IN use ANY, this also removes the need to unnest
where f.id = any (p_ids)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With