diff options
Diffstat (limited to '')
-rw-r--r-- | sqlglot/dialects/postgres.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/sqlglot/dialects/postgres.py b/sqlglot/dialects/postgres.py index 342fd95..008727c 100644 --- a/sqlglot/dialects/postgres.py +++ b/sqlglot/dialects/postgres.py @@ -22,6 +22,7 @@ from sqlglot.dialects.dialect import ( rename_func, simplify_literal, str_position_sql, + struct_extract_sql, timestamptrunc_sql, timestrtotime_sql, trim_sql, @@ -248,11 +249,10 @@ class Postgres(Dialect): } class Tokenizer(tokens.Tokenizer): - QUOTES = ["'", "$$"] - BIT_STRINGS = [("b'", "'"), ("B'", "'")] HEX_STRINGS = [("x'", "'"), ("X'", "'")] BYTE_STRINGS = [("e'", "'"), ("E'", "'")] + HEREDOC_STRINGS = ["$"] KEYWORDS = { **tokens.Tokenizer.KEYWORDS, @@ -296,7 +296,7 @@ class Postgres(Dialect): SINGLE_TOKENS = { **tokens.Tokenizer.SINGLE_TOKENS, - "$": TokenType.PARAMETER, + "$": TokenType.HEREDOC_STRING, } VAR_SINGLE_TOKENS = {"$"} @@ -420,9 +420,15 @@ class Postgres(Dialect): exp.Pow: lambda self, e: self.binary(e, "^"), exp.RegexpLike: lambda self, e: self.binary(e, "~"), exp.RegexpILike: lambda self, e: self.binary(e, "~*"), - exp.Select: transforms.preprocess([transforms.eliminate_semi_and_anti_joins]), + exp.Select: transforms.preprocess( + [ + transforms.eliminate_semi_and_anti_joins, + transforms.eliminate_qualify, + ] + ), exp.StrPosition: str_position_sql, exp.StrToTime: lambda self, e: f"TO_TIMESTAMP({self.sql(e, 'this')}, {self.format_time(e)})", + exp.StructExtract: struct_extract_sql, exp.Substring: _substring_sql, exp.TimestampTrunc: timestamptrunc_sql, exp.TimeStrToTime: timestrtotime_sql, |