diff --git a/CHANGELOG b/CHANGELOG index 38d53187..c2e3a9bc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,6 +12,7 @@ Enhancements: Some database backends love statements without semicolon (issue742). * Support TypedLiterals in get_parameters (pr649, by Khrol). * Improve splitting of Transact SQL when using GO keyword (issue762). +* Support for some JSON operators (issue682). Bug Fixes diff --git a/sqlparse/keywords.py b/sqlparse/keywords.py index 8911c7a8..9b7f8153 100644 --- a/sqlparse/keywords.py +++ b/sqlparse/keywords.py @@ -89,6 +89,8 @@ # but the match isn't a keyword. (r'\w[$#\w]*', PROCESS_AS_KEYWORD), (r'[;:()\[\],\.]', tokens.Punctuation), + # JSON operators + (r'(\->>?|#>>?|@>|<@|\?\|?|\?&|\-|#\-)', tokens.Operator), (r'[<>=~!]+', tokens.Operator.Comparison), (r'[+/@#%^&|^-]+', tokens.Operator), ] diff --git a/tests/test_parse.py b/tests/test_parse.py index be416ef2..b49dcca3 100644 --- a/tests/test_parse.py +++ b/tests/test_parse.py @@ -579,3 +579,17 @@ def test_configurable_regex(): for t in tokens if t.ttype not in sqlparse.tokens.Whitespace )[4] == (sqlparse.tokens.Keyword, "zorder by") + + +@pytest.mark.parametrize('sql', [ + '->', '->>', '#>', '#>>', + '@>', '<@', + # leaving ? out for now, they're somehow ambiguous as placeholders + # '?', '?|', '?&', + '||', '-', '#-' +]) +def test_json_operators(sql): + p = sqlparse.parse(sql) + assert len(p) == 1 + assert len(p[0].tokens) == 1 + assert p[0].tokens[0].ttype == sqlparse.tokens.Operator