Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sqlparse/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,8 @@ def get_parameters(self):
for token in parenthesis.tokens:
if isinstance(token, IdentifierList):
return token.get_identifiers()
elif imt(token, i=(Function, Identifier, TypedLiteral),
elif imt(token, i=(Function, Identifier, TypedLiteral,
Operation, Parenthesis, Case, Comparison),
t=T.Literal):
result.append(token)
return result
Expand Down
15 changes: 15 additions & 0 deletions tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@ def test_parse_function_param_single_literal():
assert t[0].ttype is T.Number.Integer


@pytest.mark.parametrize('argument, cls', [
('1 + 2', sql.Operation),
('(1 + 2)', sql.Parenthesis),
('CASE WHEN 1 THEN 2 ELSE 3 END', sql.Case),
('1 = 2', sql.Comparison),
])
def test_parse_function_param_single_grouped_expression(argument, cls):
function = sqlparse.parse(f'abs({argument})')[0].tokens[0]
parameters = list(function.get_parameters())

assert len(parameters) == 1
assert isinstance(parameters[0], cls)
assert str(parameters[0]) == argument


def test_parse_nested_function():
t = sqlparse.parse('foo(bar(5))')[0].tokens[0].get_parameters()
assert len(t) == 1
Expand Down