Mysql
 sql >> Database >  >> RDS >> Mysql

Inserimento di un elenco contenente più valori in MySQL utilizzando pymysql

vals = [["TEST1", 1], ["TEST2", 2]]

with connection.cursor() as cursor:
    cursor.executemany("insert into test(prop, val) values (%s, %s)", vals )
    connection.commit()

mysql> seleziona * da test;

+----+-------+------+---------------------+
| id | prop  | val  | ts                  |
+----+-------+------+---------------------+
|  1 | TEST1 |    1 | 2017-05-19 09:46:16 |
|  2 | TEST2 |    2 | 2017-05-19 09:46:16 |
+----+-------+------+---------------------+

Adattato da https ://groups.google.com/forum/#!searchin/pymysql-users/insert%7Csort:relevance/pymysql-users/4_D8bYusodc/EHFxjRh89XEJ