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):
623623
624624 def get_parameters (self ):
625625 """Return a list of parameters."""
626- parenthesis = self .tokens [ - 1 ]
626+ parenthesis = self .token_next_by ( i = Parenthesis )[ 1 ]
627627 result = []
628628 for token in parenthesis .tokens :
629629 if isinstance (token , IdentifierList ):
@@ -633,6 +633,13 @@ def get_parameters(self):
633633 result .append (token )
634634 return result
635635
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+
636643
637644class Begin (TokenList ):
638645 """A BEGIN/END block."""
Original file line number Diff line number Diff line change @@ -392,6 +392,14 @@ def test_grouping_function():
392392 p = sqlparse .parse ('foo(null, bar)' )[0 ]
393393 assert isinstance (p .tokens [0 ], sql .Function )
394394 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 )
395403
396404
397405def test_grouping_function_not_in ():
You can’t perform that action at this time.
0 commit comments