Skip to content

SNOW-227101: fix to datetime columns being created without timezone #202

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
13 changes: 10 additions & 3 deletions src/snowflake/sqlalchemy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,10 +634,10 @@ def visit_BLOB(self, type_, **kw):
return "BINARY"

def visit_datetime(self, type_, **kw):
return "datetime"
return self.visit_TIMESTAMP(type_, **kw)

def visit_DATETIME(self, type_, **kw):
return "DATETIME"
return self.visit_TIMESTAMP(type_, **kw)

def visit_TIMESTAMP_NTZ(self, type_, **kw):
return "TIMESTAMP_NTZ"
Expand All @@ -649,7 +649,14 @@ def visit_TIMESTAMP_LTZ(self, type_, **kw):
return "TIMESTAMP_LTZ"

def visit_TIMESTAMP(self, type_, **kw):
return "TIMESTAMP"
is_local = kw.get('is_local', False)
timezone = kw.get('timezone', type_.timezone)
return "TIMESTAMP %s%s" % (
(timezone and "WITH" or "WITHOUT") + (
is_local and " LOCAL" or "") + " TIME ZONE",
"(%d)" % type_.precision if getattr(type_, 'precision',
None) is not None else ""
)

def visit_GEOGRAPHY(self, type_, **kw):
return "GEOGRAPHY"
Expand Down
8 changes: 7 additions & 1 deletion tests/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from datetime import datetime

import pytz
from sqlalchemy import Column, Integer, MetaData, Table
from sqlalchemy import Column, Integer, MetaData, Table, DateTime
from sqlalchemy.sql import select

from snowflake.sqlalchemy import TIMESTAMP_LTZ, TIMESTAMP_NTZ, TIMESTAMP_TZ
Expand All @@ -27,6 +27,8 @@ def test_create_table_timestamp_datatypes(engine_testaccount):
Column("tsntz", TIMESTAMP_NTZ),
Column("tsltz", TIMESTAMP_LTZ),
Column("tstz", TIMESTAMP_TZ),
Column("dttz", DateTime(timezone=True)),
Column("dtntz", DateTime(timezone=False)),
)
metadata.create_all(engine_testaccount)
try:
Expand All @@ -48,6 +50,8 @@ def test_inspect_timestamp_datatypes(engine_testaccount):
Column("tsntz", TIMESTAMP_NTZ),
Column("tsltz", TIMESTAMP_LTZ),
Column("tstz", TIMESTAMP_TZ),
Column("dttz", DateTime(timezone=True)),
Column("dtntz", DateTime(timezone=False)),
)
metadata.create_all(engine_testaccount)
try:
Expand Down Expand Up @@ -79,5 +83,7 @@ def test_inspect_timestamp_datatypes(engine_testaccount):
assert rows[1] == current_utctime
assert rows[2] == current_localtime
assert rows[3] == current_localtime_with_other_tz
assert rows[4] == current_localtime_with_other_tz
assert rows[5] == current_utctime
finally:
test_timestamp.drop(engine_testaccount)