下の行のようにタイプを強制する必要があるため、以下のDateTimeタイプがDateTime(またはより適切にはTIMESTAMPタイプ)ではなく「DATE」オブジェクトを作成する理由を誰か教えてください:
#!/bin/python
import sqlalchemy
from sqlalchemy import Column, Integer, String, DateTime, Index, MetaData
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy.orm import sessionmaker
from sqlalchemy.dialects import oracle
Base = declarative_base()
import logging
logging.basicConfig()
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
class TypeTest(Base):
__tablename__ = "TYPETESTZ"
thisisinteger = Column(Integer, primary_key = True)
thisisnotadatetime = Column(DateTime)
thisisdatetime = Column(oracle.TIMESTAMP)
if __name__ == "__main__":
engine = sqlalchemy.create_engine('oracle://richard:password@xe')
metadata = Base.metadata
metadata.create_all(engine)
ログ出力:
INFO:sqlalchemy.engine.base.Engine:SELECT USER FROM DUAL
INFO:sqlalchemy.engine.base.Engine:{}
INFO:sqlalchemy.engine.base.Engine:SELECT table_name FROM all_tables WHERE table_name = :name AND owner = :schema_name
INFO:sqlalchemy.engine.base.Engine:{'name': u'TYPETESTZ', 'schema_name': u'RICHARD'}
INFO:sqlalchemy.engine.base.Engine:
CREATE TABLE "TYPETESTZ" (
thisisinteger INTEGER NOT NULL,
thisisnotadatetime DATE,
thisisdatetime TIMESTAMP,
PRIMARY KEY (thisisinteger)
)
INFO:sqlalchemy.engine.base.Engine:{}
INFO:sqlalchemy.engine.base.Engine:COMMIT