this is a documented limitation:

http://docs.sqlalchemy.org/en/rel_0_9/core/dml.html?highlight=from_select#sqlalchemy.sql.expression.Insert.from_select

Note

A SELECT..INSERT construct in SQL has no VALUES clause. Therefore Column 
objects which utilize Python-side defaults (e.g. as described at 
metadata_defaults_toplevel) will not take effect when using 
Insert.from_select().


use a server-side default instead.




On Oct 10, 2014, at 5:12 AM, gbr <[email protected]> wrote:

> Given this example, I would expect that in both cases the default value of 
> user.admin gets set.
> 
> from sqlalchemy import *
> from sqlalchemy.ext.declarative import declarative_base
> from sqlalchemy.orm import sessionmaker, scoped_session
> 
> engine = create_engine('sqlite:///:memory:', echo=True)
> Base = declarative_base(bind=engine)
> Session = scoped_session(sessionmaker(engine))
> 
> metadata = Base.metadata
> 
> user = Table('user', metadata,
> Column('id', Integer),
> Column('name', String),
> Column('admin', Boolean, default=False)
> )
> 
> metadata.create_all()
> 
> print insert(user).values({'id': 1, 'name': 'Max'})
> 
> # this is a contrived example, but it demonstrates the problem
> print insert(user).from_select([user.c.id, user.c.name], select([user.c.id, 
> user.c.name]).where(user.c.name=='Max'))
> 
> 
> The first insert() gets resolved to
> > INSERT INTO user (id, name, admin) VALUES (?, ?, ?)
> 
> which is fine, but the second intert().from_select() does not gets admin set.
> > INSERT INTO user (id, name) SELECT user.id, user.name FROM user WHERE 
> > user.name = ?
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to