diff options
| author | Federico Caselli <cfederico87@gmail.com> | 2023-01-11 20:44:07 +0100 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-01-12 10:53:53 -0500 |
| commit | a37218a8e0fa03acd0eef2d57e0294cd6e96fa84 (patch) | |
| tree | 43115cad1e5677737979d08a592fa7da682679d1 /lib/sqlalchemy/dialects/oracle | |
| parent | e636917a721f4bb01264a23736c9c81e462863cb (diff) | |
| download | sqlalchemy-a37218a8e0fa03acd0eef2d57e0294cd6e96fa84.tar.gz | |
Support local timespamp support on Oracle
Added support for the Oracle SQL type ``TIMESTAMP WITH LOCAL TIME ZONE``,
using a newly added Oracle-specific :class:`_oracle.TIMESTAMP` datatype.
Fixes: #9086
Change-Id: Ib14119503a8aaf20e1aa4e36be80ccca37383e90
Diffstat (limited to 'lib/sqlalchemy/dialects/oracle')
| -rw-r--r-- | lib/sqlalchemy/dialects/oracle/base.py | 9 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/oracle/types.py | 28 |
2 files changed, 35 insertions, 2 deletions
diff --git a/lib/sqlalchemy/dialects/oracle/base.py b/lib/sqlalchemy/dialects/oracle/base.py index d24df7ee0..65377be28 100644 --- a/lib/sqlalchemy/dialects/oracle/base.py +++ b/lib/sqlalchemy/dialects/oracle/base.py @@ -564,6 +564,7 @@ from .types import NVARCHAR2 # noqa 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 @@ -595,7 +596,6 @@ from ...types import INTEGER from ...types import NCHAR from ...types import NVARCHAR from ...types import REAL -from ...types import TIMESTAMP from ...types import VARCHAR RESERVED_WORDS = set( @@ -635,6 +635,7 @@ ischema_names = { "NCLOB": NCLOB, "TIMESTAMP": TIMESTAMP, "TIMESTAMP WITH TIME ZONE": TIMESTAMP, + "TIMESTAMP WITH LOCAL TIME ZONE": TIMESTAMP, "INTERVAL DAY TO SECOND": INTERVAL, "RAW": RAW, "FLOAT": FLOAT, @@ -681,7 +682,9 @@ class OracleTypeCompiler(compiler.GenericTypeCompiler): 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" @@ -2330,6 +2333,8 @@ class OracleDialect(default.DefaultDialect): 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: diff --git a/lib/sqlalchemy/dialects/oracle/types.py b/lib/sqlalchemy/dialects/oracle/types.py index af66d2eb4..db3d57228 100644 --- a/lib/sqlalchemy/dialects/oracle/types.py +++ b/lib/sqlalchemy/dialects/oracle/types.py @@ -5,6 +5,7 @@ # 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 @@ -216,6 +217,33 @@ class INTERVAL(sqltypes.NativeForEmulated, sqltypes._AbstractInterval): ) +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. |
