pythonsqlalchemysql-insertsinglestore

Inserting Query Results into Singlestore Table with Python and Sqlalchemy


I have parameterized queries with f strings such that the queries will select some data from a series of tables and joins, and I want to insert the resulting set of data into another pre-created table (tables been designed to house these results).

Python executes the code but the query results never show up in my table.

Assuming target_table is already created in singlestore database:

qry_load = 'insert into target_table select * from some_tables'
conn = engine.connect()
trans = conn.begin()
try:
    conn.execute(qry_load)
    trans.commit()
except:
    trans.rollback()
    raise

The code executes and acts as if all is ok, but the data never shows up in the target table.

How do I see what singlestore is passing back to better debug what is happening within the database?


Solution

  • Just replace begin() with cursor() function:

    conn = engine.connect()
    trans = conn.cursor()
    

    If not resolved

    1- Verify structure of source and destination tables if they are same or not.

    2- remove try ,except and rollback() block so you can know the actual error.

    Ex.

    qry_load = 'insert into target_table select * from some_tables'
    conn = engine.connect()
    trans = conn.cursor()
    conn.execute(qry_load)
    trans.commit()