Try this
http://www.sqlalchemy.org/docs/05/reference/ext/compiler.html?highlight=compiler#compiling-sub-elements-of-a-custom-expression-construct


--
Abdul Kader

On Wed, Nov 3, 2010 at 5:09 PM, Torsten Landschoff
<torsten.landsch...@dynamore.de> wrote:
>
> Hi *,
>
> I am wondering if there is a way to generate an insert from select with 
> SQLAlchemy. Consider this code:
>
> from sqlalchemy import *
>
> engine = create_engine("sqlite:///demo.ldb", echo=True)
>
> md = MetaData()
> users = Table("users", md,
>     Column("id", Integer, primary_key=True),
>     Column("name", String),
>     Column("status", Integer))
> md.create_all(engine)
>
> engine.execute(users.insert().values(name="Joe Sixpack", status=1))
> engine.execute(users.insert().values(name="Jane Citizen", status=1))
>
> # insert from select?
> # engine.execute(users.insert().values(
> #      users.select([users.c.name]), status=2))
>
> conn = engine.connect()
> with conn.begin():
>     for row in conn.execute(users.select()).fetchall():
>         conn.execute(users.insert().values(
>             name=row["name"], status=2))
>
> Is there a way to generate the "natural" SQL for this:
>
> insert into users (name, status) select name, 2 as status from users
>
> Basically I would like to tell SQLAlchemy to use a query to provide the 
> values for insert. StackOverflow says this can't be done, but I can't believe 
> that. :-)
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to