I have a requirement to connect to two Databases's and copy data over from source DB(Postgres) to Target DB (MySQL)
I am getting an error
TypeError: can only concatenate str (not "list") to str
When I try to generate an insert query when copying data from source to target
I am able to connect to the databases successfully, so that's not an issue
def query_sql(connection, query):
cursor = connection.cursor()
cursor.execute(query)
return cursor.fetchall()
def insert_to_target_table(data):
insert_sql = "INSERT INTO " + schema + "." + target_table + " SELECT * FROM " + data
execute_query(db_connection, insert_sql)
full_data = query_sql(postgres_connection, "SELECT * from "+schema+"."+src_table+";")
insert_to_target_table(full_data)
I know the full_data is returned as a list and that's giving the error Is there any other way by converting type or using pandas that this can be achieved?
I have also recently worked on same thing, I can help you with this code of mine, I edit it a bit for you.It will help you to copy your data from postgres database to mysql using python language
To transfer data between the two databases, this code uses psycopg2 for PostgreSQL and mysql-connector-python for MySQL. Your actual database connection information and table names should be used in place of the placeholder values.
Hope it works :)