Skip to content

Commit 28a2acd

Browse files
John Bodleyandialbrecht
authored andcommitted
[fix] Adding TypedLiteral to comparison
1 parent 6e39e02 commit 28a2acd

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

sqlparse/engine/grouping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def post(tlist, pidx, tidx, nidx):
192192

193193
def group_comparison(tlist):
194194
sqlcls = (sql.Parenthesis, sql.Function, sql.Identifier,
195-
sql.Operation)
195+
sql.Operation, sql.TypedLiteral)
196196
ttypes = T_NUMERICAL + T_STRING + T_NAME
197197

198198
def match(token):

tests/test_grouping.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_grouping_assignment(s):
3636
@pytest.mark.parametrize('s', ["x > DATE '2020-01-01'", "x > TIMESTAMP '2020-01-01 00:00:00'"])
3737
def test_grouping_typed_literal(s):
3838
parsed = sqlparse.parse(s)[0]
39-
assert isinstance(parsed[4], sql.TypedLiteral)
39+
assert isinstance(parsed[0][4], sql.TypedLiteral)
4040

4141

4242
@pytest.mark.parametrize('s, a, b', [
@@ -550,6 +550,17 @@ def test_comparison_with_functions():
550550
assert p.tokens[0].right.value == 'bar.baz'
551551

552552

553+
def test_comparison_with_typed_literal():
554+
p = sqlparse.parse("foo = DATE 'bar.baz'")[0]
555+
assert len(p.tokens) == 1
556+
comp = p.tokens[0]
557+
assert isinstance(comp, sql.Comparison)
558+
assert len(comp.tokens) == 5
559+
assert comp.left.value == 'foo'
560+
assert isinstance(comp.right, sql.TypedLiteral)
561+
assert comp.right.value == "DATE 'bar.baz'"
562+
563+
553564
@pytest.mark.parametrize('start', ['FOR', 'FOREACH'])
554565
def test_forloops(start):
555566
p = sqlparse.parse('{0} foo in bar LOOP foobar END LOOP'.format(start))[0]

0 commit comments

Comments
 (0)