<p dir="auto"><strong>Migrated issue, originally created by Dave Hirschfeld</strong></p>
<p dir="auto">As detailed in <a href="https://github.com/zzzeek/sqlalchemy/pull/382" data-hovercard-type="pull_request" data-hovercard-url="/zzzeek/sqlalchemy/pull/382/hovercard">GH#382</a> the <code class="notranslate">dialects.mssql.TIMESTAMP</code> class is a direct import of the <code class="notranslate">sa.sql.sqltypes.TIMESTAMP</code> class into the <code class="notranslate">mssql</code> namespace.</p>
<p dir="auto">The fact that the <code class="notranslate">mssql.TIMESTAMP</code> class is the same as the <code class="notranslate">sqltypes.TIMESTAMP</code> class causes problems in a 3rd party library, <a href="https://github.com/blaze/odo">odo</a> which operates by mapping sqlalchemy types to the corresponding python/numpy types.</p>
<p dir="auto">The reason this causes problem is that unlike the ANSI SQL <code class="notranslate">TIMESTAMP</code> the <code class="notranslate">mssql.TIMESTAMP</code> type <em>doesn't</em> represent a datetime object but is instead just a binary type which cannot be interpreted or converted to a datetime object.</p>
<p dir="auto">This problem doesn't affect sqlalchemy itself because sqlalchemy  emits the correct <code class="notranslate">TIMESTAMP</code> DDL and then simply passes through the results from the underlying driver.</p>
<p dir="auto">With <code class="notranslate">type(sqltypes.TIMESTAMP) == type(mssql.TIMESTAMP)</code> being true there is no way for odo to distinguish the two types. Because one represents a Python datetime object and the other a byte string they need to be able to be distinguished and handled differently in odo.</p>
<p dir="auto">A sufficient condition for odo to correctly handle MSSQL TIMESTAMP types is that the <code class="notranslate">mssql.TIMESTAMP</code> class does not inherit from the <code class="notranslate">sqltypes.TIMESTAMP</code> class - e.g.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="def test_mssql_timestamp_is_not_timestamp():
    &quot;&quot;&quot;The MSSQL TIMESTAMP type does *not* represent a datetime value
    so should not inherit from the `sqltypes.TIMESTAMP` class

    :ref: https://msdn.microsoft.com/en-us/library/ms182776%28v=SQL.90%29.aspx
    &quot;&quot;&quot;
    from sqlalchemy.sql import sqltypes
    from sqlalchemy.dialects import mssql
    assert not issubclass(mssql.TIMESTAMP, sqltypes.TIMESTAMP)"><pre class="notranslate"><span class="pl-k">def</span> <span class="pl-en">test_mssql_timestamp_is_not_timestamp</span>():
    <span class="pl-s">"""The MSSQL TIMESTAMP type does *not* represent a datetime value</span>
<span class="pl-s">    so should not inherit from the `sqltypes.TIMESTAMP` class</span>
<span class="pl-s"></span>
<span class="pl-s">    :ref: https://msdn.microsoft.com/en-us/library/ms182776%28v=SQL.90%29.aspx</span>
<span class="pl-s">    """</span>
    <span class="pl-k">from</span> <span class="pl-s1">sqlalchemy</span>.<span class="pl-s1">sql</span> <span class="pl-k">import</span> <span class="pl-s1">sqltypes</span>
    <span class="pl-k">from</span> <span class="pl-s1">sqlalchemy</span>.<span class="pl-s1">dialects</span> <span class="pl-k">import</span> <span class="pl-s1">mssql</span>
    <span class="pl-k">assert</span> <span class="pl-c1">not</span> <span class="pl-en">issubclass</span>(<span class="pl-s1">mssql</span>.<span class="pl-v">TIMESTAMP</span>, <span class="pl-s1">sqltypes</span>.<span class="pl-v">TIMESTAMP</span>)</pre></div>
<p dir="auto"><strong>Migrated issue, originally created by Dan Stovall</strong></p>
<p dir="auto">In MSSQL a ROWVERSION or TIMESTAMP column do not contain a date time.  Instead the contain an 8-byte integer.  Currently, the column is set as sqlachemy.sql.sqltypes.TIMESTAMP, which is an instance of the DateTime type.  Running a query against a table with such a column returns a byte string value for those columns.  The mssql dialect should probably have a specific ROWVERSION type and it should be an integer, not a DateTime.  Also, it would be nice if the values of those columns returned an integer by using int.from_bytes to convert the byte string.</p>