Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(teradata): use timestamp with time zone over timestamptz #3723

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion sqlglot/dialects/teradata.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,13 @@ class Generator(generator.Generator):
TABLESAMPLE_KEYWORDS = "SAMPLE"
LAST_DAY_SUPPORTS_DATE_PART = False
CAN_IMPLEMENT_ARRAY_ANY = True
TZ_TO_WITH_TIME_ZONE = True

TYPE_MAPPING = {
**generator.Generator.TYPE_MAPPING,
exp.DataType.Type.GEOMETRY: "ST_GEOMETRY",
exp.DataType.Type.DOUBLE: "DOUBLE PRECISION",
exp.DataType.Type.TIMESTAMPTZ: "TIMESTAMP",
}

PROPERTIES_LOCATION = {
Expand All @@ -254,7 +256,7 @@ class Generator(generator.Generator):
exp.ToChar: lambda self, e: self.function_fallback_sql(e),
exp.ToNumber: to_number_with_nls_param,
exp.Use: lambda self, e: f"DATABASE {self.sql(e, 'this')}",
exp.CurrentTimestamp: lambda *_: "CURRENT_TIMESTAMP",
exp.CurrentTimestamp: lambda self, e: "CURRENT_TIMESTAMP" if not e.this else f"CURRENT_TIMESTAMP({self.sql(e, 'this')})",
georgesittas marked this conversation as resolved.
Show resolved Hide resolved
exp.DateAdd: _date_add_sql("+"),
exp.DateSub: _date_add_sql("-"),
exp.Quarter: lambda self, e: self.sql(exp.Extract(this="QUARTER", expression=e.this)),
Expand Down
3 changes: 2 additions & 1 deletion tests/dialects/test_teradata.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def test_teradata(self):
"teradata": "RANDOM(l, u)",
},
)

self.validate_identity("TO_NUMBER(expr, fmt, nlsparam)")
self.validate_identity("SELECT TOP 10 * FROM tbl")
self.validate_identity("SELECT * FROM tbl SAMPLE 5")
Expand Down Expand Up @@ -220,6 +219,8 @@ def test_cast(self):
)

def test_time(self):
self.validate_identity("CAST(CURRENT_TIMESTAMP(6) AS TIMESTAMP WITH TIME ZONE)")

self.validate_all(
"CURRENT_TIMESTAMP",
read={
Expand Down
Loading