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

Feat!: add support for heredoc strings (Postgres, ClickHouse) #2328

Merged
merged 3 commits into from
Sep 26, 2023

Conversation

georgesittas
Copy link
Collaborator

@georgesittas georgesittas commented Sep 26, 2023

Fixes #2316 - planning to do another pass on this and double-check some changed tests etc.

cc: @pkit

References:

@@ -248,11 +248,10 @@ class Postgres(Dialect):
}

class Tokenizer(tokens.Tokenizer):
QUOTES = ["'", "$$"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was incorrect before?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more like partially correct; it didn't take into account tagged heredocs like the following:

georgesittas=# select $foo$this is a string$foo$;
     ?column?
------------------
 this is a string
(1 row)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -207,7 +207,6 @@ def test_postgres(self):
self.validate_identity("SELECT ARRAY[1, 2, 3] @> ARRAY[1, 2]")
self.validate_identity("SELECT ARRAY[1, 2, 3] <@ ARRAY[1, 2]")
self.validate_identity("SELECT ARRAY[1, 2, 3] && ARRAY[1, 2]")
self.validate_identity("$x")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is invalid postgres:

georgesittas=# select $x;
ERROR:  syntax error at or near "$"
LINE 1: select $x;

@@ -226,7 +226,6 @@ def test_identity(self):
self.validate_identity("SELECT * FROM #x")
self.validate_identity("SELECT INTERVAL '5 day'")
self.validate_identity("foo$")
self.validate_identity("$foo")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is invalid Redshift
Screenshot 2023-09-26 at 8 48 57 PM

@georgesittas georgesittas merged commit ebdfc59 into main Sep 26, 2023
@georgesittas georgesittas deleted the jo/support_heredocs branch September 26, 2023 18:09
@pkit
Copy link
Contributor

pkit commented Sep 26, 2023

Yup, works fine for my use case. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clickhouse: heredoc is not parsable
3 participants