Im trying to input many rows to a table in a mariaDB. For doing this i want to use executemany() to increase speed. The inserted row is dependent on another table, which is found with SELECT. I have found statements that SELECT doent work in a executemany(). Are there other ways to sole this problem?
import mariadb
connection = mariadb.connect(host=HOST,port=PORT,user=USER,password=PASSWORD,database=DATABASE)
cursor = connection.cursor()
query="""INSERT INTO [db].[table1] ([col1], [col2] ,[col3])
VALUES ((SELECT [colX] from [db].[table2] WHERE [colY]=? and
[colZ]=(SELECT [colM] from [db].[table3] WHERE [colN]=?)),?,?)
ON DUPLICATE KEY UPDATE
[col2]= ?,
[col3] =?;"""
values=[input_tuplets]
When running the code i get the same value for [col1] (the SELECT-statement) which corresponds to the values from the from the first tuplet.
If SELECT doent work in a executemany() are there another workaround for what im trying to do? Thx alot!
execute_many()is used. One way aound this would be to find another way of doing this without using select. Any ideas?CREATE TABLE region (id INT(6) AUTO_INCREMENT PRIMARY KEY,id_country INT(6),region VARCHAR(30))CREATE TABLE countries (id INT(6) AUTO_INCREMENT PRIMARY KEY, country VARCHAR(30))insert into countries (country) values ("ger"),("fra")insert into region (region,id_country) values ("sounth",(select id from countries where country="ger"))