Skip to content

Commit 25dabec

Browse files
committed
Improve parsing of string literals in columns.
1 parent 524a1e5 commit 25dabec

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Development
44
Bug Fixes
55
* Fix incorrect parsing of string literals containing line breaks (issue118).
66
* Fix typo in keywords, add MERGE keywords (issue122, by Cristian Orellana).
7+
* Improve parsing of string literals in columns.
78

89
Enhancements
910
* Classify DML keywords (issue116, by Victor Hahn).

sqlparse/engine/grouping.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ def _consume_cycle(tl, i):
157157
lambda y: (y.ttype in (T.String.Symbol,
158158
T.Name,
159159
T.Wildcard,
160+
T.Literal.String.Single,
160161
T.Literal.Number.Integer,
161162
T.Literal.Number.Float)
162163
or isinstance(y, (sql.Parenthesis, sql.Function)))))

tests/test_grouping.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ def test_identifier_with_op_trailing_ws():
238238
assert p.tokens[1].ttype is T.Whitespace
239239

240240

241+
def test_identifier_with_string_literals():
242+
p = sqlparse.parse('foo + \'bar\'')[0]
243+
assert len(p.tokens) == 1
244+
assert isinstance(p.tokens[0], sql.Identifier)
245+
246+
241247
# This test seems to be wrong. It was introduced when fixing #53, but #111
242248
# showed that this shouldn't be an identifier at all. I'm leaving this
243249
# commented in the source for a while.

0 commit comments

Comments
 (0)