0

I want to do an insert into a table from a select from another couple of tables. Something similar to:

INSERT INTO 
`table_b`
SELECT table_a.id, props.description
FROM
    table_a
JOIN 
    props 
    ON props.el_id = table_a.id;

How can I do this using SQL Expression Language? I'm talking about SQLAlchemy here.

I know there's a

db.execute(insert(table_b).values(id=20, description="another row"))

But I cant find a way to use a select expression to get the data to be inserted.

SiddharthaRT
  • 2,217
  • 4
  • 20
  • 28
  • I'm only about 90% sure this is a dup; if that doesn't answer your question, let me know and I'll vote to reopen. (Look at the "Another Edit" part of the accepted answer, assuming you have sqlalchemy 0.8.3 or later.) – abarnert Apr 17 '15 at 17:54
  • It is indeed a duplicate. Thanks! I'll try and report if the 'another edit' part solution works. – SiddharthaRT Apr 17 '15 at 18:37

0 Answers0