summaryrefslogtreecommitdiffstats
path: root/sqlglot/dialects/postgres.py
diff options
context:
space:
mode:
Diffstat (limited to 'sqlglot/dialects/postgres.py')
-rw-r--r--sqlglot/dialects/postgres.py21
1 files changed, 2 insertions, 19 deletions
diff --git a/sqlglot/dialects/postgres.py b/sqlglot/dialects/postgres.py
index a092cad..f3fec31 100644
--- a/sqlglot/dialects/postgres.py
+++ b/sqlglot/dialects/postgres.py
@@ -10,6 +10,7 @@ from sqlglot.dialects.dialect import (
no_tablesample_sql,
no_trycast_sql,
str_position_sql,
+ trim_sql,
)
from sqlglot.helper import seq_get
from sqlglot.tokens import TokenType
@@ -81,23 +82,6 @@ def _substring_sql(self, expression):
return f"SUBSTRING({this}{from_part}{for_part})"
-def _trim_sql(self, expression):
- target = self.sql(expression, "this")
- trim_type = self.sql(expression, "position")
- remove_chars = self.sql(expression, "expression")
- collation = self.sql(expression, "collation")
-
- # Use TRIM/LTRIM/RTRIM syntax if the expression isn't postgres-specific
- if not remove_chars and not collation:
- return self.trim_sql(expression)
-
- trim_type = f"{trim_type} " if trim_type else ""
- remove_chars = f"{remove_chars} " if remove_chars else ""
- from_part = "FROM " if trim_type or remove_chars else ""
- collation = f" COLLATE {collation}" if collation else ""
- return f"TRIM({trim_type}{remove_chars}{from_part}{target}{collation})"
-
-
def _string_agg_sql(self, expression):
expression = expression.copy()
separator = expression.args.get("separator") or exp.Literal.string(",")
@@ -248,7 +232,6 @@ class Postgres(Dialect):
"COMMENT ON": TokenType.COMMAND,
"DECLARE": TokenType.COMMAND,
"DO": TokenType.COMMAND,
- "DOUBLE PRECISION": TokenType.DOUBLE,
"GENERATED": TokenType.GENERATED,
"GRANT": TokenType.COMMAND,
"HSTORE": TokenType.HSTORE,
@@ -318,7 +301,7 @@ class Postgres(Dialect):
exp.Substring: _substring_sql,
exp.TimeToStr: lambda self, e: f"TO_CHAR({self.sql(e, 'this')}, {self.format_time(e)})",
exp.TableSample: no_tablesample_sql,
- exp.Trim: _trim_sql,
+ exp.Trim: trim_sql,
exp.TryCast: no_trycast_sql,
exp.UnixToTime: lambda self, e: f"TO_TIMESTAMP({self.sql(e, 'this')})",
exp.DataType: _datatype_sql,