File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -623,7 +623,7 @@ class Function(NameAliasMixin, TokenList):
623
623
624
624
def get_parameters (self ):
625
625
"""Return a list of parameters."""
626
- parenthesis = self .tokens [ - 1 ]
626
+ parenthesis = self .token_next_by ( i = Parenthesis )[ 1 ]
627
627
result = []
628
628
for token in parenthesis .tokens :
629
629
if isinstance (token , IdentifierList ):
@@ -633,6 +633,13 @@ def get_parameters(self):
633
633
result .append (token )
634
634
return result
635
635
636
+ def get_window (self ):
637
+ """Return the window if it exists."""
638
+ over_clause = self .token_next_by (i = Over )
639
+ if not over_clause :
640
+ return None
641
+ return over_clause [1 ].tokens [- 1 ]
642
+
636
643
637
644
class Begin (TokenList ):
638
645
"""A BEGIN/END block."""
Original file line number Diff line number Diff line change @@ -392,6 +392,14 @@ def test_grouping_function():
392
392
p = sqlparse .parse ('foo(null, bar)' )[0 ]
393
393
assert isinstance (p .tokens [0 ], sql .Function )
394
394
assert len (list (p .tokens [0 ].get_parameters ())) == 2
395
+ p = sqlparse .parse ('foo(5) over win1' )[0 ]
396
+ assert isinstance (p .tokens [0 ], sql .Function )
397
+ assert len (list (p .tokens [0 ].get_parameters ())) == 1
398
+ assert isinstance (p .tokens [0 ].get_window (), sql .Identifier )
399
+ p = sqlparse .parse ('foo(5) over (PARTITION BY c1)' )[0 ]
400
+ assert isinstance (p .tokens [0 ], sql .Function )
401
+ assert len (list (p .tokens [0 ].get_parameters ())) == 1
402
+ assert isinstance (p .tokens [0 ].get_window (), sql .Parenthesis )
395
403
396
404
397
405
def test_grouping_function_not_in ():
You can’t perform that action at this time.
0 commit comments