diff options
Diffstat (limited to 'sqlglot/optimizer/canonicalize.py')
-rw-r--r-- | sqlglot/optimizer/canonicalize.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/sqlglot/optimizer/canonicalize.py b/sqlglot/optimizer/canonicalize.py index faf18c6..0aa8134 100644 --- a/sqlglot/optimizer/canonicalize.py +++ b/sqlglot/optimizer/canonicalize.py @@ -38,7 +38,12 @@ def replace_date_funcs(node: exp.Expression) -> exp.Expression: if isinstance(node, exp.Date) and not node.expressions and not node.args.get("zone"): return exp.cast(node.this, to=exp.DataType.Type.DATE) if isinstance(node, exp.Timestamp) and not node.expression: - return exp.cast(node.this, to=exp.DataType.Type.TIMESTAMP) + if not node.type: + from sqlglot.optimizer.annotate_types import annotate_types + + node = annotate_types(node) + return exp.cast(node.this, to=node.type or exp.DataType.Type.TIMESTAMP) + return node @@ -76,9 +81,8 @@ def coerce_type(node: exp.Expression) -> exp.Expression: def remove_redundant_casts(expression: exp.Expression) -> exp.Expression: if ( isinstance(expression, exp.Cast) - and expression.to.type and expression.this.type - and expression.to.type.this == expression.this.type.this + and expression.to.this == expression.this.type.this ): return expression.this return expression |