3

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))
$$;
 
 
 
 
diziaq
  • 6,881
  • 16
  • 54
  • 96

1 Answers1

6

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

where f.id = any (p_ids)