diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-02-10 21:57:44 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-02-10 21:57:44 -0500 |
commit | 020d6ef8f017d4411b403c18d93f913d6b01fd62 (patch) | |
tree | 15cb1d36599dcadc5cac2c7d857d44d006c346c5 /lib/sqlalchemy/sql/compiler.py | |
parent | ad8700a556d3ec9368dd80238dfddf456eeccd5f (diff) | |
download | sqlalchemy-020d6ef8f017d4411b403c18d93f913d6b01fd62.tar.gz |
- Added over() function, method to FunctionElement
classes, produces the _Over() construct which
in turn generates "window functions", i.e.
"<window function> OVER (PARTITION BY <partition by>,
ORDER BY <order by>)".
[ticket:1844]
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 1ab0ba405..781072dd0 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -446,12 +446,14 @@ class SQLCompiler(engine.Compiled): if clause.value is not None: x += clause.value._compiler_dispatch(self, **kwargs) + " " for cond, result in clause.whens: - x += "WHEN " + cond._compiler_dispatch(self, **kwargs) + \ - " THEN " + \ - result._compiler_dispatch(self, **kwargs) + " " + x += "WHEN " + cond._compiler_dispatch( + self, **kwargs + ) + " THEN " + result._compiler_dispatch( + self, **kwargs) + " " if clause.else_ is not None: - x += "ELSE " + clause.else_._compiler_dispatch(self, **kwargs) + \ - " " + x += "ELSE " + clause.else_._compiler_dispatch( + self, **kwargs + ) + " " x += "END" return x @@ -460,6 +462,19 @@ class SQLCompiler(engine.Compiled): (cast.clause._compiler_dispatch(self, **kwargs), cast.typeclause._compiler_dispatch(self, **kwargs)) + def visit_over(self, over, **kwargs): + x ="%s OVER (" % over.func._compiler_dispatch(self, **kwargs) + if over.partition_by is not None: + x += "PARTITION BY %s" % \ + over.partition_by._compiler_dispatch(self, **kwargs) + if over.order_by is not None: + x += ", " + if over.order_by is not None: + x += "ORDER BY %s" % \ + over.order_by._compiler_dispatch(self, **kwargs) + x += ")" + return x + def visit_extract(self, extract, **kwargs): field = self.extract_map.get(extract.field, extract.field) return "EXTRACT(%s FROM %s)" % (field, |