diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-03-12 10:17:16 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-03-12 10:17:16 +0000 |
commit | 7457677bc603569692329e39a59ccb018306e2a6 (patch) | |
tree | bb16c8f909bfbf7ff272cd8ef14a413c47b203fe /sqlglot/generator.py | |
parent | Releasing debian version 11.3.3-1. (diff) | |
download | sqlglot-7457677bc603569692329e39a59ccb018306e2a6.tar.xz sqlglot-7457677bc603569692329e39a59ccb018306e2a6.zip |
Merging upstream version 11.3.6.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/generator.py')
-rw-r--r-- | sqlglot/generator.py | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/sqlglot/generator.py b/sqlglot/generator.py index 4504e95..5936649 100644 --- a/sqlglot/generator.py +++ b/sqlglot/generator.py @@ -59,7 +59,6 @@ class Generator: exp.DateAdd: lambda self, e: self.func( "DATE_ADD", e.this, e.expression, e.args.get("unit") ), - exp.DateDiff: lambda self, e: self.func("DATEDIFF", e.this, e.expression), exp.TsOrDsAdd: lambda self, e: self.func( "TS_OR_DS_ADD", e.this, e.expression, e.args.get("unit") ), @@ -109,9 +108,6 @@ class Generator: # Whether or not create function uses an AS before the RETURN CREATE_FUNCTION_RETURN_AS = True - # Whether or not to treat the division operator "/" as integer division - INTEGER_DIVISION = True - # Whether or not MERGE ... WHEN MATCHED BY SOURCE is allowed MATCHED_BY_SOURCE = True @@ -1571,7 +1567,7 @@ class Generator: ) else: this = "" - unit = expression.args.get("unit") + unit = self.sql(expression, "unit") unit = f" {unit}" if unit else "" return f"INTERVAL{this}{unit}" @@ -1757,25 +1753,17 @@ class Generator: return f"{self.sql(expression, 'this')} RESPECT NULLS" def intdiv_sql(self, expression: exp.IntDiv) -> str: - div = self.binary(expression, "/") - return self.sql(exp.Cast(this=div, to=exp.DataType.build("INT"))) + return self.sql( + exp.Cast( + this=exp.Div(this=expression.this, expression=expression.expression), + to=exp.DataType(this=exp.DataType.Type.INT), + ) + ) def dpipe_sql(self, expression: exp.DPipe) -> str: return self.binary(expression, "||") def div_sql(self, expression: exp.Div) -> str: - div = self.binary(expression, "/") - - if not self.INTEGER_DIVISION: - return self.sql(exp.Cast(this=div, to=exp.DataType.build("INT"))) - - return div - - def floatdiv_sql(self, expression: exp.FloatDiv) -> str: - if self.INTEGER_DIVISION: - this = exp.Cast(this=expression.this, to=exp.DataType.build("DOUBLE")) - return self.div_sql(exp.Div(this=this, expression=expression.expression)) - return self.binary(expression, "/") def overlaps_sql(self, expression: exp.Overlaps) -> str: @@ -1991,3 +1979,9 @@ class Generator: using = f"USING {self.sql(expression, 'using')}" on = f"ON {self.sql(expression, 'on')}" return f"MERGE INTO {this} {using} {on} {self.expressions(expression, sep=' ')}" + + def tochar_sql(self, expression: exp.ToChar) -> str: + if expression.args.get("format"): + self.unsupported("Format argument unsupported for TO_CHAR/TO_VARCHAR function") + + return self.sql(exp.cast(expression.this, "text")) |