title: SQLAlchemy - copy schema and data of subquery to another database
body: <p>I am trying to copy data from a subquery from postgres (from_engine) to sqlite database.  I can achieve this for copying a table using following command:</p>
  
  <pre><code>smeta = MetaData(bind=from_engine)
  table = Table(table_name, smeta, autoload=True)
  table.metadata.create_all(to_engine)
  </code></pre>
  
  <p>However, I am not sure how to achieve the same for a subquery statement.</p>
  
  <p>-Sandeep</p>
  
  <p>Edit:
  Follow up on the answer.  Once I have created the table I want to create a subquery stmt as follows:</p>
  
  <pre><code>table = Table("newtable", dest_metadata, *columns)
  stmt = dest_session.query(table).subquery();
  </code></pre>
  
  <p>However, the last stmt ends up with error
  cursor.execute(statement, parameters)
  sqlalchemy.exc.ProgrammingError: (ProgrammingError) relation "newtable" does not exist
  LINE 3: FROM newtable) AS anon_1</p>