Can do one better by just passing the filter expression.
table_filter = Widget.id < 5000
passing table_filter as an optional parameter to column_windows, the
interval query becomes
q = session.query(
column,
func.row_number().\
over(order_by=column).\
label('rownum')
) if table_filter is not None: q =
q.filter(table_filter)
q = q.from_self(column)
This applies the WHERE clause directly without needing a JOIN
The SQL statement with the example table_filter above is
SELECT anon_1.widget_id AS anon_1_widget_id
FROM (
SELECT widget.id AS widget_id, row_number() OVER (ORDER BY widget.id) AS
rownum
FROM widget
WHERE widget.id < :id_1) AS anon_1
WHERE rownum % 1000=1
or if table_filter is None:
SELECT anon_1.widget_id AS anon_1_widget_id
FROM (
SELECT widget.id AS widget_id, row_number() OVER (ORDER BY widget.id) AS
rownum
FROM widget) AS anon_1
WHERE rownum % 1000=1
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.