I’m trying to reproduce this simplified Postgres query in Django (where [v1, v2, ...]
is a python list):
SELECT * FROM UNNEST(ARRAY[v1, v2, ...]) objs (obj)
WHERE EXISTS(
SELECT "table"."field1"
FROM "table"
WHERE "table"."field2" = 'value' AND "table"."field1" = fp
)
But I cannot find a way to use UNNEST(ARRAY(...
on something that is not a table.
2
Answers
For this i use common table expression (CTE) :
then in query use RIGHT JOIN
full query:
ARRAY(subquery)
is special array constructor that requires relation.