summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql/compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-08-25 09:41:18 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2017-08-25 09:42:25 -0400
commit3a5bbe4cbe12d180fba2b942d0467b46be705bea (patch)
tree7613927bb275e4b53712cb28c15a1b3f2abe50bd /lib/sqlalchemy/sql/compiler.py
parente33cff44b5822a22c540d316151699203a1fff52 (diff)
downloadsqlalchemy-3a5bbe4cbe12d180fba2b942d0467b46be705bea.tar.gz
Allow for multiple FOLLOWING/PRECEDING in a window range
Altered the range specification for window functions to allow for two of the same PRECEDING or FOLLOWING keywords in a range by allowing for the left side of the range to be positive and for the right to be negative, e.g. (1, 3) is "1 FOLLOWING AND 3 FOLLOWING". Change-Id: I7d3a6c641151bb49219104968d18dac2266f3db8 Fixes: #4053
Diffstat (limited to 'lib/sqlalchemy/sql/compiler.py')
-rw-r--r--lib/sqlalchemy/sql/compiler.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 53009e2df..2dec3a5c3 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -848,16 +848,25 @@ class SQLCompiler(Compiled):
cast.typeclause._compiler_dispatch(self, **kwargs))
def _format_frame_clause(self, range_, **kw):
+
return '%s AND %s' % (
"UNBOUNDED PRECEDING"
if range_[0] is elements.RANGE_UNBOUNDED
else "CURRENT ROW" if range_[0] is elements.RANGE_CURRENT
- else "%s PRECEDING" % (self.process(range_[0], **kw), ),
+ else "%s PRECEDING" % (
+ self.process(elements.literal(abs(range_[0])), **kw), )
+ if range_[0] < 0
+ else "%s FOLLOWING" % (
+ self.process(elements.literal(range_[0]), **kw), ),
"UNBOUNDED FOLLOWING"
if range_[1] is elements.RANGE_UNBOUNDED
else "CURRENT ROW" if range_[1] is elements.RANGE_CURRENT
- else "%s FOLLOWING" % (self.process(range_[1], **kw), )
+ else "%s PRECEDING" % (
+ self.process(elements.literal(abs(range_[1])), **kw), )
+ if range_[1] < 0
+ else "%s FOLLOWING" % (
+ self.process(elements.literal(range_[1]), **kw), ),
)
def visit_over(self, over, **kwargs):