This is horrible, but it works ( after a few hours of trial & error )

the trick was in using labels and aliases in every step

it makes perfect sense looking at it now ( though ugly ), but was not how i 
expected to pull this off.

For anyone who gets stuck:

    if _query_A and _query_B :
        _slurped = sqlalchemy.union( _query_A , _query_B )
        _slurped = sqlalchemy.sql.expression.alias( _slurped , 
name='slurped')
        _culled = sqlalchemy.select(\
                ( sqlalchemy.sql.distinct(_slurped.c.id).label('id') , 
_slurped.c.event_timestamp.label('event_timestamp') )
            )\
            .order_by(\
                _slurped.c.id.desc(), 
                _slurped.c.event_timestamp.desc()
            )
        _culled = sqlalchemy.sql.expression.alias( _culled , name='culled')
        _ordered = sqlalchemy.select( (_culled.c.id,) )\
            .order_by(\
                _culled.c.event_timestamp.desc()
            )
        _ordered = sqlalchemy.sql.expression.alias( _ordered , 
name='ordered')
        _query = _ordered

    else :
        if _query_A :
            _query = _query_A\
                .order_by(\
                    model.core.ObjA.timestamp_a.desc()
                )
        elif _query_B :
            _query = _query_B\
                .order_by(\
                    model.core.ObjB.timestamp_b.desc()
                )

    if isinstance( _query , sqlalchemy.orm.query.Query ):
        items_count = _query.count()
    else:
        items_count = dbSession.( _query.count() )

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to