--- /dev/null
+.. change::
+ :tags: oracle, usecase
+ :tickets: 9086
+
+ Added support for the Oracle SQL type ``TIMESTAMP WITH LOCAL TIME ZONE``,
+ using a newly added Oracle-specific :class:`_oracle.TIMESTAMP` datatype.
.. autoclass:: RAW
:members: __init__
+.. autoclass:: TIMESTAMP
+ :members: __init__
+
.. _cx_oracle:
cx_Oracle
from .types import OracleRaw # noqa
from .types import RAW
from .types import ROWID # noqa
+from .types import TIMESTAMP
from .types import VARCHAR2 # noqa
from ... import Computed
from ... import exc
from ...types import NCHAR
from ...types import NVARCHAR
from ...types import REAL
-from ...types import TIMESTAMP
from ...types import VARCHAR
RESERVED_WORDS = set(
"NCLOB": NCLOB,
"TIMESTAMP": TIMESTAMP,
"TIMESTAMP WITH TIME ZONE": TIMESTAMP,
+ "TIMESTAMP WITH LOCAL TIME ZONE": TIMESTAMP,
"INTERVAL DAY TO SECOND": INTERVAL,
"RAW": RAW,
"FLOAT": FLOAT,
return "LONG"
def visit_TIMESTAMP(self, type_, **kw):
- if type_.timezone:
+ if getattr(type_, "local_timezone", False):
+ return "TIMESTAMP WITH LOCAL TIME ZONE"
+ elif type_.timezone:
return "TIMESTAMP WITH TIME ZONE"
else:
return "TIMESTAMP"
coltype = self.ischema_names.get(coltype)(char_length)
elif "WITH TIME ZONE" in coltype:
coltype = TIMESTAMP(timezone=True)
+ elif "WITH LOCAL TIME ZONE" in coltype:
+ coltype = TIMESTAMP(local_timezone=True)
else:
coltype = re.sub(r"\(\d+\)", "", coltype)
try:
# the MIT License: https://www.opensource.org/licenses/mit-license.php
# mypy: ignore-errors
+from ... import exc
from ...sql import sqltypes
from ...types import NVARCHAR
from ...types import VARCHAR
)
+class TIMESTAMP(sqltypes.TIMESTAMP):
+ """Oracle implementation of ``TIMESTAMP``, which supports additional
+ Oracle-specific modes
+
+ .. versionadded:: 2.0
+
+ """
+
+ def __init__(self, timezone: bool = False, local_timezone: bool = False):
+ """Construct a new :class:`_oracle.TIMESTAMP`.
+
+ :param timezone: boolean. Indicates that the TIMESTAMP type should
+ use Oracle's ``TIMESTAMP WITH TIME ZONE`` datatype.
+
+ :param local_timezone: boolean. Indicates that the TIMESTAMP type
+ should use Oracle's ``TIMESTAMP WITH LOCAL TIME ZONE`` datatype.
+
+
+ """
+ if timezone and local_timezone:
+ raise exc.ArgumentError(
+ "timezone and local_timezone are mutually exclusive"
+ )
+ super().__init__(timezone=timezone)
+ self.local_timezone = local_timezone
+
+
class ROWID(sqltypes.TypeEngine):
"""Oracle ROWID type.
Column("d3", TIMESTAMP),
Column("d4", TIMESTAMP(timezone=True)),
Column("d5", oracle.INTERVAL(second_precision=5)),
+ Column("d6", oracle.TIMESTAMP(local_timezone=True)),
)
metadata.create_all(connection)
m = MetaData()
assert isinstance(t1.c.d1.type, DateTime)
assert isinstance(t1.c.d2.type, oracle.DATE)
assert isinstance(t1.c.d2.type, DateTime)
- assert isinstance(t1.c.d3.type, TIMESTAMP)
+ assert isinstance(t1.c.d3.type, oracle.TIMESTAMP)
assert not t1.c.d3.type.timezone
- assert isinstance(t1.c.d4.type, TIMESTAMP)
+ assert isinstance(t1.c.d4.type, oracle.TIMESTAMP)
assert t1.c.d4.type.timezone
+ assert isinstance(t1.c.d6.type, oracle.TIMESTAMP)
+ assert t1.c.d6.type.local_timezone
assert isinstance(t1.c.d5.type, oracle.INTERVAL)
def _dont_test_reflect_all_types_schema(self):