Skip to content

Instantly share code, notes, and snippets.

@tombohub
Created April 18, 2021 13:12
Show Gist options
  • Save tombohub/5653577369b6a22ed7f46fc45a4fe7e2 to your computer and use it in GitHub Desktop.
Save tombohub/5653577369b6a22ed7f46fc45a4fe7e2 to your computer and use it in GitHub Desktop.

Revisions

  1. tombohub renamed this gist Apr 18, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. tombohub created this gist Apr 18, 2021.
    19 changes: 19 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    from sqlalchemy import create_engine
    from sqlalchemy.sql.expression import select

    db1_uri = 'db_uri_here'
    db2_uri = 'db_uri_here'

    db1_engine = create_engine(db1_uri)
    db2_engine = create_engine(db2_uri)

    db1_conn = db1_engine.connect()
    db2_conn = db2_engine.connect()

    table = 'table_name_here'
    query = select(table_name)

    df = pd.read_sql(query, db1_conn)
    df.to_sql(table, db2_conn, index=False)

    # repeat for each table, change table name