Skip to content

Commit dc2329d

Browse files
Khrolandialbrecht
authored andcommitted
Support TypedLiterals in get_parameters
1 parent 8d34105 commit dc2329d

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

sqlparse/sql.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -619,12 +619,13 @@ class Function(NameAliasMixin, TokenList):
619619
def get_parameters(self):
620620
"""Return a list of parameters."""
621621
parenthesis = self.tokens[-1]
622+
result = []
622623
for token in parenthesis.tokens:
623624
if isinstance(token, IdentifierList):
624625
return token.get_identifiers()
625-
elif imt(token, i=(Function, Identifier), t=T.Literal):
626-
return [token, ]
627-
return []
626+
elif imt(token, i=(Function, Identifier, TypedLiteral), t=T.Literal):
627+
result.append(token)
628+
return result
628629

629630

630631
class Begin(TokenList):

tests/test_parse.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ def test_parse_nested_function():
133133
assert type(t[0]) is sql.Function
134134

135135

136+
def test_parse_casted_params():
137+
t = sqlparse.parse("foo(DATE '2023-11-14', TIMESTAMP '2023-11-15')")[0].tokens[0].get_parameters()
138+
assert len(t) == 2
139+
140+
136141
def test_parse_div_operator():
137142
p = sqlparse.parse('col1 DIV 5 AS div_col1')[0].tokens
138143
assert p[0].tokens[0].tokens[2].ttype is T.Operator

0 commit comments

Comments
 (0)