E
E
ediboba2020-05-19 16:09:06
Python
ediboba, 2020-05-19 16:09:06

How to execute insert from list of RowProxy in SQLAlchemy?

I do a raw select into a remote table (maybe fields are sometimes added or deleted in a table), and then I want to make an insert into my table

data = remote_session.execute("SELECT key1, key2 FROM table").fetchall()
insert_stmt = insert(Table).values(data)
local_session.execute(insert_stmt)

eventually throws an exception
Could not locate column in row for column 'translate'

But if you translate it into a dict, then everything is good
data = remote_session.execute("SELECT key1, key2 FROM table").fetchall()
for key, value in enumerate(data):
       data[key] = dict(value)
insert_stmt = insert(Table).values(data)
local_session.execute(insert_stmt)


Can it be done without bypassing data?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question