Skip to content

Commit 43975e4

Browse files
authored
fix(duckdb): Allow escape strings similar to Postgres (#4497)
1 parent ab10851 commit 43975e4

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

sqlglot/dialects/duckdb.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ def to_json_path(self, path: t.Optional[exp.Expression]) -> t.Optional[exp.Expre
297297
return super().to_json_path(path)
298298

299299
class Tokenizer(tokens.Tokenizer):
300+
BYTE_STRINGS = [("e'", "'"), ("E'", "'")]
300301
HEREDOC_STRINGS = ["$"]
301302

302303
HEREDOC_TAG_IS_IDENTIFIER = True

tests/dialects/test_duckdb.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,16 @@ def test_duckdb(self):
899899
"NOT a ILIKE b",
900900
)
901901

902+
self.validate_all(
903+
"SELECT e'Hello\nworld'",
904+
read={
905+
"duckdb": "SELECT E'Hello\nworld'",
906+
},
907+
write={
908+
"duckdb": "SELECT e'Hello\nworld'",
909+
},
910+
)
911+
902912
def test_array_index(self):
903913
with self.assertLogs(helper_logger) as cm:
904914
self.validate_all(

0 commit comments

Comments
 (0)