sqlalchemy supports INSERT INTO ... (SELECT .. ) ?

631 views
Skip to first unread message

Kent

unread,
Mar 30, 2012, 6:05:29 PM3/30/12
to sqlal...@googlegroups.com
Couldn't find answer in docs, does sqlalchemy support:

INSERT INTO ... (SELECT .. )

instead of

INSERT INTO ... VALUES...

Michael Bayer

unread,
Mar 30, 2012, 6:40:09 PM3/30/12
to sqlal...@googlegroups.com
its not built in at the moment but there is a recipe in the docs for @compiles


kind of amazing nobody's yet contributed a patch for this, I show people that recipe for a few years now :)


--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/IIxzN-i9740J.
To post to this group, send email to sqlal...@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.

Kent Bower

unread,
Mar 30, 2012, 6:43:35 PM3/30/12
to sqlal...@googlegroups.com
Thanks for pointing me there.  As an aside, the recipe would be more bulletproof if it specified the columns (order).  Currently, it assumes sqlalchemy knows the order of the columns in the database, which it may not.

Thanks again!

Michael Bayer

unread,
Mar 30, 2012, 6:58:35 PM3/30/12
to sqlal...@googlegroups.com
so many great ideas for the eventual contributor ! ;)

ideally it would be a method on insert() itself, table.insert().from(select([...])..., cols=('x', 'y', 'z')) or something like that.   Maybe people have suggestions.

Kent Bower

unread,
Mar 30, 2012, 7:15:10 PM3/30/12
to sqlal...@googlegroups.com
Yeah, I knew it was a hint... ;)   So many great ideas, so little time. :(
Reply all
Reply to author
Forward
0 new messages