Stack Acc
Stack Acc

Reputation: 79

Convert array to list in Postgres for select query

In PostgreSQL I am trying to convert an array to a list say I have an array: v_arr

I want to use this array in the below query in Postgres:

Select * 
from table_name 
where column_name in (v_arr)

Upvotes: 5

Views: 12194

Answers (2)

Alberto_Contreras
Alberto_Contreras

Reputation: 59

You could use unnest

SELECT * 
FROM table_name 
WHERE column_name IN (SELECT unnest(v_arr));

https://www.postgresql.org/docs/current/static/functions-array.html

Upvotes: 5

Lukasz Szozda
Lukasz Szozda

Reputation: 176124

You could use = ANY:

Select * from table_name where column_name = any (v_arr);

db<>fiddle demo

Upvotes: 3

Related Questions