- changed milestone to 0.6.xx
support for postgresql windowing functions
PG8.4 ref: http://www.postgresql.org/docs/8.4/static/tutorial-window.html
It would be nice to have support for window functions in the expression language.
Thanks!
gregg.lind@gmail.com
Comments (10)
-
repo owner -
Account Deleted This seems like part of the way there:
from sqlalchemy.ext.compiler import compiles from sqlalchemy.sql.expression import Executable, ClauseElement, ClauseList, _generative from sqlalchemy import util class Over(Executable, ClauseList): def __init__(self, *column_or_columns): ClauseList.__init__(self,*util.to_list(column_or_columns) or [ self.over_clause = ClauseList(*util.to_list(column_or_columns) or [](]) )) @compiles(Over) def visit_over(grouping, compiler, asfrom=False, **kwargs): return "OVER (PARTITION BY " + compiler.process(grouping.over_clause, **kwargs) + ")"
Gregg L.
-
Account Deleted From where I'm looking at things... it looks like it's very hard to add new methods onto select and friends... I'm wondering if there could be a decorator, similar to '_generative' that would note that a function can be 'chained'.... thus
select([some_column_set](some_column_set)).over(some_col1)
would have some parts like this:@chainable class Over(Executable, ClauseList):
and in
select
and friends:def getattr(self,attr): if attr in global_chainables_registry: return ...
I realize I'm being a bit vague, and this might warrant a larger discussion!
Gregg
-
repo owner - marked as critical
-
repo owner sorry, those are WITH queries, not the same thing as windowing functions. windowing functions are not as tough to implement.
-
repo owner - changed component to sql
and WITH is over in
#1859 -
repo owner also I just had to use a window the other day, its pretty easy in the usual case,
from_self()
makes the usual "subquery from self" a snap:for x, in Session.query(SomeClass.x, literal_column("ROW_NUMBER OVER (ORDER BY foo.bar) AS rownum")).\ from_self(SomeClass.x).\ filter("rownum %% %d=1" % modulus)
-
repo owner - changed milestone to 0.7.0
putting this on 0.7.0 for the moment, will force me to look at it, see if I can do it with a clause element. I am using window functions right now across PG / SQL Server. Perhaps supporting just the OVER (expression) version to start, with WINDOW coming in later.
select([table.c.b.over(order_by=table.c.c)](table.c.a,)) select([table.c.b.over(partition_by=table.c.c)](table.c.a,)) w = window(partition_by=table.c.a, order_by=table.c.b.desc()) select([table.c.b.over(w)](table.c.a,))
-
repo owner - changed status to resolved
that syntax above is a little misguided. OVER is always against a window or aggregate function. So it looks like this:
select([func.rank().over(partition_by=table.c.b)](table.c.a,))
-
repo owner - removed milestone
Removing milestone: 0.7.0 (automated comment)
- Log in to comment