Skip to content

Commit

Permalink
allow operators to procede dollar quoted strings
Browse files Browse the repository at this point in the history
  • Loading branch information
proddata authored and andialbrecht committed Mar 5, 2024
1 parent f101546 commit ab84201
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Enhancements:
Bug Fixes

* Ignore dunder attributes when creating Tokens (issue672).
* Allow operators to precede dollar-quoted strings (issue763).


Release 0.4.4 (Apr 18, 2023)
Expand Down
2 changes: 1 addition & 1 deletion sqlparse/keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

(r"`(``|[^`])*`", tokens.Name),
(r"´(´´|[^´])*´", tokens.Name),
(r'((?<!\S)\$(?:[_A-ZÀ-Ü]\w*)?\$)[\s\S]*?\1', tokens.Literal),
(r'((?<![\w\"\$])\$(?:[_A-ZÀ-Ü]\w*)?\$)[\s\S]*?\1', tokens.Literal),

(r'\?', tokens.Name.Placeholder),
(r'%(\(\w+\))?s', tokens.Name.Placeholder),
Expand Down
8 changes: 8 additions & 0 deletions tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ def test_psql_quotation_marks():
$PROC_2$ LANGUAGE plpgsql;""")
assert len(t) == 2

# operators are valid infront of dollar quoted strings
t = sqlparse.split("""UPDATE SET foo =$$bar;SELECT bar$$""")
assert len(t) == 1

# identifiers must be separated by whitespace
t = sqlparse.split("""UPDATE SET foo TO$$bar;SELECT bar$$""")
assert len(t) == 2


def test_double_precision_is_builtin():
s = 'DOUBLE PRECISION'
Expand Down

0 comments on commit ab84201

Please sign in to comment.