I have the following simplified query
WITH users as (
SELECT *
FROM users
WHERE created_at >= '2024-01-01'
)
SELECT *
FROM emails
WHERE user_id = ANY(ARRAY(SELECT id FROM users))
I need to use ANY(ARRAY())
over a simple IN
since this forces the optimizer to take a better plan that makes a significant impact.
How do I convert this into SQLAlchemy?
I tried something like this but it keeps failing
users_cte = select(User.id, User.name).filter(User.created_at >= date(2024, 01, 01)).cte("user_cte")
select(
emails.address
)
.filter(Email.user_id.any_(func.array(select(users.cte.id))))
This results in
TypeError: ColumnOperators.any_() takes 1 positional argument but 2 were given
Is this possible to do in sqlalchemy?