Re: [sqlalchemy] skipping MSSQL TIMESTAMP column on INSERT

2015-12-11 Thread mdob
@event.listens_for(Table, 'column_reflect') def receive_column_reflect(inspector, table, column_info): if isinstance(column_info['type'], TIMESTAMP): column_info['default'] = FetchedValue() table = Table(table_name, metadata, autoload=True, autoload_with=engine,

Re: [sqlalchemy] skipping MSSQL TIMESTAMP column on INSERT

2015-12-11 Thread Mike Bayer
On 12/11/2015 01:12 PM, mdob wrote: > | > > @event.listens_for(Table,'column_reflect') > defreceive_column_reflect(inspector,table,column_info): > ifisinstance(column_info['type'],TIMESTAMP): > column_info['default']=FetchedValue() > the reflection wants to assume the

Re: [sqlalchemy] skipping MSSQL TIMESTAMP column on INSERT

2015-12-11 Thread mdob
Maybe this should go into server_default. Because cole belowe worked fine. for col in table.columns: if isinstance(col.type, TIMESTAMP): col.server_default = FetchedValue() Updating column_info['server_default'] = FetchedValue() in event handler didn't work. On Friday, December

Re: [sqlalchemy] skipping MSSQL TIMESTAMP column on INSERT

2014-11-14 Thread Michael Bayer
probably (maybe we should improve on our end, though). but when you’re autoloading, you can set this default up automatically using the column_reflect event: http://docs.sqlalchemy.org/en/rel_0_9/core/events.html?highlight=column_reflect#sqlalchemy.events.DDLEvents.column_reflect

Re: [sqlalchemy] skipping MSSQL TIMESTAMP column on INSERT

2011-09-25 Thread Matt Bodman
Thanks so much Michael.. just to wrap up this thread, I got it working like this: class Thing(Base): __tablename__ = 'tbThings' __table_args__ = ( {'autoload':True,'autoload_with':engine,'extend_existing':True} ) LastUpdated = Column('LastUpdated', TIMESTAMP,

[sqlalchemy] skipping MSSQL TIMESTAMP column on INSERT

2011-09-15 Thread Matt Bodman
Hi, I am autoloading tables from an MSSQL db. A lot of the tables have the MSSQL TIMESTAMP column. So, when inserting to the table, I get an IntegrityError: sqlalchemy.exc.IntegrityError: (IntegrityError) ('23000', '[23000] [FreeTDS][SQL Server]Cannot insert an explicit value into a timestamp

Re: [sqlalchemy] skipping MSSQL TIMESTAMP column on INSERT

2011-09-15 Thread Michael Bayer
Ideally this TIMESTAMP column would have a default declared at the server level: CREATE TABLE mytable ( ... some_timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP ) otherwise you're using python-side defaults, so you'd need to write a post-table processing function: from sqlalchemy import

Re: [sqlalchemy] skipping MSSQL TIMESTAMP column on INSERT

2011-09-15 Thread Matt Bodman
Hi Michael, Thanks for your reply. Please be patient with me though as I don't quite get it. Where and when is the add_default function called? Won't I get the same error trying to insert 'some default' into the column? Any further explanation would be great. Matt -- You received this

Re: [sqlalchemy] skipping MSSQL TIMESTAMP column on INSERT

2011-09-15 Thread Michael Bayer
you'd call it as soon as you reflect your table. my_table = Table('some_table', metadata, autoload=True) add_default(my_table) probably worthwhile to make a function: def reflect_table(name, metadata): my_table = Table('some_table', metadata, autoload=True) add_default(my_table)

Re: [sqlalchemy] skipping MSSQL TIMESTAMP column on INSERT

2011-09-15 Thread Michael Bayer
On Sep 15, 2011, at 10:51 AM, Matt Bodman wrote: Hi Michael, Thanks for your reply. Please be patient with me though as I don't quite get it. Where and when is the add_default function called? Won't I get the same error trying to insert 'some default' into the column? Any