4

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))
$$;
 
 
 
 

1 Answer 1

10

Don't use IN use ANY, this also removes the need to unnest

where f.id = any (p_ids)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.