1.0 is a real thing but it's unreleased :)    more of an "early next year" 
thing hopefully

you can put the defaults in the SELECT manually for now as another option.




On Oct 10, 2014, at 6:28 PM, gbr <[email protected]> wrote:

> I didn't know 1.0 was out already. How can I upgrade to it? `pip` and 
> `easy_install` still install 0.9.7...
> 
> On Saturday, 11 October 2014 08:50:05 UTC+11, Michael Bayer wrote:
> I've implemented this feature in 1.0.   When you upgrade to 1.0, the default 
> values will be included in the SELECT statement automatically.
> 
> See 
> http://docs.sqlalchemy.org/en/latest/changelog/migration_10.html#insert-from-select-now-includes-python-and-sql-expression-defaults
>  .
> 
> 
> 
> On Oct 10, 2014, at 10:39 AM, Michael Bayer <[email protected]> wrote:
> 
>> 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.
> 
> 
> -- 
> 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