Skip to content

Commit 6b05583

Browse files
committed
Add support for some of the JSON operators (fixes andialbrecht#682).
1 parent 5bb129d commit 6b05583

3 files changed

Lines changed: 17 additions & 0 deletions

File tree

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Enhancements:
1212
Some database backends love statements without semicolon (issue742).
1313
* Support TypedLiterals in get_parameters (pr649, by Khrol).
1414
* Improve splitting of Transact SQL when using GO keyword (issue762).
15+
* Support for some JSON operators (issue682).
1516

1617
Bug Fixes
1718

sqlparse/keywords.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@
8989
# but the match isn't a keyword.
9090
(r'\w[$#\w]*', PROCESS_AS_KEYWORD),
9191
(r'[;:()\[\],\.]', tokens.Punctuation),
92+
# JSON operators
93+
(r'(\->>?|#>>?|@>|<@|\?\|?|\?&|\-|#\-)', tokens.Operator),
9294
(r'[<>=~!]+', tokens.Operator.Comparison),
9395
(r'[+/@#%^&|^-]+', tokens.Operator),
9496
]

tests/test_parse.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,3 +579,17 @@ def test_configurable_regex():
579579
for t in tokens
580580
if t.ttype not in sqlparse.tokens.Whitespace
581581
)[4] == (sqlparse.tokens.Keyword, "zorder by")
582+
583+
584+
@pytest.mark.parametrize('sql', [
585+
'->', '->>', '#>', '#>>',
586+
'@>', '<@',
587+
# leaving ? out for now, they're somehow ambiguous as placeholders
588+
# '?', '?|', '?&',
589+
'||', '-', '#-'
590+
])
591+
def test_json_operators(sql):
592+
p = sqlparse.parse(sql)
593+
assert len(p) == 1
594+
assert len(p[0].tokens) == 1
595+
assert p[0].tokens[0].ttype == sqlparse.tokens.Operator

0 commit comments

Comments
 (0)