when you say a.union(b.union(c)) there is a predictable ordering to
those. its confusing for sure but its not unlike when you string
together things like "A JOIN B JOIN C" etc.
for now I would recommend experimenting with the underlyting
selectable object used by a union so you can get a feel for it (we
can then add on intersect() and except_clause() methods at some point)
from sqlalchemy.sql import CompoundSelect
a = mytable.select()
b = select(<someotherstuff>)
c = ....
q = CompoundSelect('UNION', a, b)
x = CompoundSelect('INTERSECT', q, c)
y = CompoundSelect('EXCEPT', x, d, g, h, i)
y.execute()
On Jun 13, 2006, at 9:58 PM, Charles Duffy wrote:
> I'm looking at writing a TurboGears-based application where I'll have
> cause to use not only UNION but also INTERSECT and EXCEPT. The
> SQLAlchemy documentation appears to indicate that only UNION is
> supported.
>
> Is there any chance of INTERSECT or EXCEPT showing up in future
> versions
> of SQLAlchemy? If a patch should be straightforward to write, I
> wouldn't
> mind trying my hand at one.
>
>
> Also -- whereas with UNION alone there's little need to control
> nesting
> order, when one adds INTERSECT and EXCEPT in it can be important to
> specify that one wants (A UNION B) INTERSECT C as opposed to A
> UNION (B
> INTERSECT C); at least in PostgreSQL, INTERSECT binds tighter. I
> imagine
> that the natural syntax for combining UNIONs and INTERSECTs would be
> something like the following:
>
> users.select(
> users.c.city == 'Austin'
> ).union(
> users.select(users.c.city == 'Houston')
> ).intersect(
> users.select(users.c.age < 17)
> )
>
> ...however, I don't see a plain way to clarify whether the
> intersect or
> the union should happen first.
>
>
>
> _______________________________________________
> Sqlalchemy-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users