Skip to content

Commit 8c24779

Browse files
committed
Improve formatting of statements with JSON operators (fixes andialbrecht#542).
1 parent 6b05583 commit 8c24779

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Enhancements:
1313
* Support TypedLiterals in get_parameters (pr649, by Khrol).
1414
* Improve splitting of Transact SQL when using GO keyword (issue762).
1515
* Support for some JSON operators (issue682).
16+
* Improve formatting of statements containing JSON operators (issue542).
1617

1718
Bug Fixes
1819

sqlparse/engine/grouping.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,12 @@ def post(tlist, pidx, tidx, nidx):
139139

140140
def group_period(tlist):
141141
def match(token):
142-
return token.match(T.Punctuation, '.')
142+
for ttype, value in ((T.Punctuation, '.'),
143+
(T.Operator, '->'),
144+
(T.Operator, '->>')):
145+
if token.match(ttype, value):
146+
return True
147+
return False
143148

144149
def valid_prev(token):
145150
sqlcls = sql.SquareBrackets, sql.Identifier
@@ -153,7 +158,7 @@ def valid_next(token):
153158
def post(tlist, pidx, tidx, nidx):
154159
# next_ validation is being performed here. issue261
155160
sqlcls = sql.SquareBrackets, sql.Function
156-
ttypes = T.Name, T.String.Symbol, T.Wildcard
161+
ttypes = T.Name, T.String.Symbol, T.Wildcard, T.String.Single
157162
next_ = tlist[nidx] if nidx is not None else None
158163
valid_next = imt(next_, i=sqlcls, t=ttypes)
159164

0 commit comments

Comments
 (0)