我有一个包含user_ids
列的表,这是一个Postgres数组。
我需要从另一个表中选择所有messages
,其中列user_id
是给定数组中的一个ID。
在Psuedo-sql中:
select users.*
from users
where id IN a_postgres_array
有什么想法吗?
答案 0 :(得分:1)
您可以使用ANY
运算符。来自您的样本:
select users.*
from users
where id =ANY(a_postgres_array)
使用两个表时,它可能是JOIN
,类似于:
SELECT users.*
FROM users INNER JOIN table_with_array ON users.id =ANY(table_with_array.a_postgres_array)
答案 1 :(得分:0)
select users.*
from users
where id IN (
select unnest(a_postgres_array)
from t
where columnX = some_value
)