diff options
Diffstat (limited to 'sqlglot/dialects/postgres.py')
-rw-r--r-- | sqlglot/dialects/postgres.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/sqlglot/dialects/postgres.py b/sqlglot/dialects/postgres.py index 8d84024..8c2a4ab 100644 --- a/sqlglot/dialects/postgres.py +++ b/sqlglot/dialects/postgres.py @@ -183,9 +183,10 @@ def _to_timestamp(args: t.List) -> exp.Expression: class Postgres(Dialect): - null_ordering = "nulls_are_large" - time_format = "'YYYY-MM-DD HH24:MI:SS'" - time_mapping = { + INDEX_OFFSET = 1 + NULL_ORDERING = "nulls_are_large" + TIME_FORMAT = "'YYYY-MM-DD HH24:MI:SS'" + TIME_MAPPING = { "AM": "%p", "PM": "%p", "D": "%u", # 1-based day of week @@ -241,7 +242,6 @@ class Postgres(Dialect): "REFRESH": TokenType.COMMAND, "REINDEX": TokenType.COMMAND, "RESET": TokenType.COMMAND, - "RETURNING": TokenType.RETURNING, "REVOKE": TokenType.COMMAND, "SERIAL": TokenType.SERIAL, "SMALLSERIAL": TokenType.SMALLSERIAL, @@ -258,6 +258,7 @@ class Postgres(Dialect): class Parser(parser.Parser): STRICT_CAST = False + CONCAT_NULL_OUTPUTS_STRING = True FUNCTIONS = { **parser.Parser.FUNCTIONS, @@ -268,6 +269,7 @@ class Postgres(Dialect): "NOW": exp.CurrentTimestamp.from_arg_list, "TO_CHAR": format_time_lambda(exp.TimeToStr, "postgres"), "TO_TIMESTAMP": _to_timestamp, + "UNNEST": exp.Explode.from_arg_list, } FUNCTION_PARSERS = { @@ -303,7 +305,7 @@ class Postgres(Dialect): value = self._parse_bitwise() if part and part.is_string: - part = exp.Var(this=part.name) + part = exp.var(part.name) return self.expression(exp.Extract, this=part, expression=value) @@ -328,6 +330,7 @@ class Postgres(Dialect): **generator.Generator.TRANSFORMS, exp.BitwiseXor: lambda self, e: self.binary(e, "#"), exp.ColumnDef: transforms.preprocess([_auto_increment_to_serial, _serial_to_generated]), + exp.Explode: rename_func("UNNEST"), exp.JSONExtract: arrow_json_extract_sql, exp.JSONExtractScalar: arrow_json_extract_scalar_sql, exp.JSONBExtract: lambda self, e: self.binary(e, "#>"), |