I have a query of this form:
SELECT models.oid
FROM models
WHERE _type='Task' AND
status NOT IN ['complete', 'removed'] AND
creator.`$ref`='wm'
EXCEPT
SELECT fromRef.oid
(complex situation)
This query has two pieces. Each work separately correctly. Trouble is, when the second EXCEPT part returns a legitimate empty answer [], the whole query is broken.
Suppose the first query returns:
[ {oid: 'A' }, { oid: 'B' } ]
Now, in the case where the second query returns []
the result of the whole thing is []
! That’s the issue.
In the case where the second query returns [ {oid: 'A' } ]
then you get the result you expect, which is [ { oid: 'B' } ]
.
What am I missing here?
For extra weirdness, if I take out the second part and reformulate it to just be SELECT [] from models
then the whole query works.