[Sqlalchemy-tickets] Issue #4044: SQLite, CREATE TABLE AS and DATETIME: TypeError: must be real num
Brought to you by:
zzzeek
From: Brecht M. <iss...@bi...> - 2017-08-14 09:26:09
|
New issue 4044: SQLite, CREATE TABLE AS and DATETIME: TypeError: must be real number, not str https://bitbucket.org/zzzeek/sqlalchemy/issues/4044/sqlite-create-table-as-and-datetime Brecht Machiels: The following fails with SQLALchemy 1.1.11, 1.1.13 and 1.2.0b2. I'm running CPython 3.6.1 (conda-forge, 64-bit on Windows 7). ``` #!python from datetime import datetime from sqlalchemy import create_engine, MetaData, Table, Column, DateTime engine = create_engine('sqlite:///:memory:') meta = MetaData(bind=engine) mytable = Table('mytable', meta, Column('dt', DateTime)) meta.create_all() engine.execute(mytable.insert().values(dt=datetime(1982, 10, 1, 10, 00, 00))) for row in engine.execute(mytable.select()): print(row) engine.execute('CREATE TABLE mytable2 AS SELECT * FROM mytable') # (works) using the DBAPI connection conn = engine.connect() for row in conn.execute('SELECT * FROM mytable2'): print(row) # (fails) using SQLAlchemy mytable2 = Table('mytable2', meta, autoload=True) for row in engine.execute(mytable2.select()): print(row) ``` Stack trace: ``` #! C:\Users\bmachie\AppData\Local\Continuum\Miniconda3\envs\ml_irissearch\lib\site-packages\sqlalchemy\sql\sqltypes.py:596: SAWarning: Dialect sqlite+pysqlite does *not* support Decimal objects natively, and SQLAlchemy must convert from floating point - rounding errors and other issues may occur. Please consider storing Decimal numbers as strings or integers on this platform for lossless storage. 'storage.' % (dialect.name, dialect.driver)) Traceback (most recent call last): File "C:/Users/bmachie/.PyCharmCE2017.2/config/scratches/scratch_6.py", line 30, in <module> print(row) File "C:\Users\bmachie\AppData\Local\Continuum\Miniconda3\envs\ml_irissearch\lib\site-packages\sqlalchemy\engine\result.py", line 156, in __repr__ return repr(sql_util._repr_row(self)) File "C:\Users\bmachie\AppData\Local\Continuum\Miniconda3\envs\ml_irissearch\lib\site-packages\sqlalchemy\sql\util.py", line 325, in __repr__ ", ".join(trunc(value) for value in self.row), TypeError: must be real number, not str ``` |