Insert into () SELECT & SELECT INTO

Issue #722 resolved
Former user created an issue

A simple and nice feature to have is a way to construct SQL expressions for Insert into SELECT and SELECT INTO Statements.

The interface would be as simple as:

insert(<selectable>)

I don't imagine it would be that hard to do, mostly since I already did it, by extracting the selectable's text:

sql = "INSERT INTO %(table)s %(columns)s %(select_stmt)" % (<table>, <columns>, str(<selectable>) % <selectable>.compile().get_params() )

conn.execute(sql)

However, this seems "wrong" - in many ways. Hence I'd like to be able to simply say:

conn.execute(insert(<selectable>))

For a select into statement, probably a select() keyword like:

select(<columns>,<where>,into_table=<new_table_name>)

Comments (4)

  1. Former user Account Deleted

    Along these lines being able to generate a CREATE TABLE ... AS select-statement clause with:

    • table.create(<selectable>)

    would be very nice.

  2. Mike Bayer repo owner

    its sort of a "blue sky" for me but is a pretty common expression construct so putting in on the 0.6 track for now.

  3. Log in to comment