Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow operators to procede dollar quoted strings #764

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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