Set combination are not semantically correct
The following example:
from querybuilder.helpers import table
@table
class t:
id: int
name: str
qsmall = t.select(where=t.c.id.lt(16))
qlarge = t.select(where=t.c.id.gt(32))
qpaper = t.select(where=t.c.name.ilike('%paper%'))
q0 = qsmall.union(qlarge).intersect(qpaper)
q1 = qsmall.union(qlarge.intersect(qpaper))
print(q0)
print(q1)
give twice the query:
SELECT t.id, t.name FROM t WHERE t.id < 16 UNION SELECT t.id, t.name FROM t WHERE t.id > 32 UNION SELECT t.id, t.name FROM t WHERE t.name ILIKE ?
However, the semantics should be distinct:
assert q0.left == qsmall.union(qlarge)
assert q0.right == qpaper
assert q1.left == qsmall
assert q1.right == qpaper.intersect(qlarge)
In fact, the right member of a set combination should be a Select
query, not itself a set combination (although we might accept, in methods union
/intersect
/except
/…_all
, a set combination that uses same set combinator). Should it be checked at instantiation?