2

I'm trying to use SQLAlchemy to create a table from a SELECT clause as in the following query:

CREATE TABLE new_table AS 
  SELECT foo, bar, baz
  FROM other_table
  WHERE foo > 50

I know that I can run a CREATE TABLE, then SELECT and finally INSERT, but this will ultimately be working with large quantities of data so bringing it into memory is not desirable. Equally I don't want to construct a text query and execute that.

3
  • 1
    Try this? Commented Dec 3, 2020 at 15:59
  • @AdamKG That could work. I'm still not 100% happy with that solution since it's still executing a string but it's definitely an improvement on an un-parameterised string and perhaps it is the best I can do right now. Commented Dec 3, 2020 at 17:00
  • Did you find any better solution? Commented Jun 11, 2022 at 1:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.