Hello.
I am trying to adapt WindowedRangeQuery recipe
http://www.sqlalchemy.org/trac/wiki/UsageRecipes/WindowedRangeQuery
I have just stumbled upon the following issue:
def _q_windows(self, window_size):
q = self._query.with_entities(
self._column,
func.row_number().over(order_by=self._column).label('rownum'),
)
if window_size > 1:
q = q.filter("rownum % {} = 1".format(window_size))
return q
where
self._query = session.query(Foo)
self._column = Foo.id
window_size = 2
The returned query q produces the following SQL:
SELECT
foo.id AS foo_id,
row_number() OVER (ORDER BY foo.id) AS rownum
FROM foo
WHERE rownum % 2 = 1
When executed, it generates the following error:
sqlalchemy.exc.ProgrammingError:
(ProgrammingError) column "rownum" does not exist
I am kind of lost here, because something very similar should work according to
the original recipe. Note that I apply with_entities() on the original query
whereas the recipe uses from_self() on the column.
Do you have any idea what should I do to fix this?
Thank you in advance,
Ladislav Lenart
--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.