MariaDB的允许使用内部INSERT https://mariadb.com/kb/en/library/dynamic-columns/从蟒插入到MariaDB的动态柱(COLUMN_CREATE)
COLUMN_CREATE功能在BLOB列插入的名称 - 值对实施例
CREATE TABLE T (id int, v blob);
INSERT INTO T (id,v) VALUES(1, COLUMN_CREATE('color', 'blue', 'size', 'XL'));
我无法从蟒做到这一点:
import mysql.connector
cnx = mysql.connector.connect (host=.., user=‘.., password=.., port=.., database=..)
cursor = cnx.cursor()
SQL='INSERT INTO T (id,v) VALUES(%s,COLUMN_CREATE(%s))'
data=[(10,'"X",2'),(20,'"Y",1')] # <---- I think problem is here
cursor.executemany(SQL,data)
cursor.close()
cnx.commit()
cnx.close()
我得到了一个错误:
mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')),(20,COLUMN_CREATE('\"Y\",1'))' at line 1
从上述错误消息我看到\(反斜杠)被自动插入(通过驱动程序?)
如何将数据传递给玛丽亚的COLUMN_CREATE功能,使其工作? 我试图改变单引号和双引号:它没有帮助。
当像'data'的结构通过“%s的格式在Python会发生什么“? –
该软件包解决了这个问题:https://pypi.python.org/pypi/mariadb-dyncol 它将python字典转换为内部MariaDB动态列格式 – user510040
如果是这样,那么将其作为答案提供给您的问题。 (可以自行回答。) –