嗨,我正在尝试以下脚本import psycopg2 as pqimport os# Create the databaseos.system('dropdb ptest')os.system('createdb ptest')# connect to the databasecn = pq.connect('dbname=ptest user=myname')cr = cn.cursor()# the wierd tuple at the EOL below is to preserve the list # lookup in case that is where the error is.cr.execute('CREATE TABLE id1 (%s varchar, %s int PRIMARY KEY, %s int, %s int, %s varchar)' % tuple(['fund', 'sleeve_id', 'sub_id', 'level_id', 'Entity_id'])cr.execute('INSERT INTO id1 (%s,%s,%s,%s,%s) VALUES ("%s","%s","%s","%s","%s");' % tuple(['fund', 'sleeve_id', 'sub_id', 'level_id', 'Entity_id']+['RHUBARB RHUBARB - RHUBARB RHUBARB', '2', '1', '1', 'CRUMB1']))我得到了错误Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<string>", line 1, in <module>psycopg2.InternalError: current transaction is aborted, commands ignored until end of transaction block我究竟做错了什么?顺便说一句,行发生相同的错误cr.execute('INSERT INTO id1 (%s,%s,%s,%s,%s) VALUES ("%s","%s","%s","%s","%s");' % ('fund', 'sleeve_id', 'sub_id', 'level_id', 'Entity_id','RHUBARB RHUBARB - RHUBARB RHUBARB', '2', '1', '1', 'CRUMB1'))
添加回答
举报
0/150
提交
取消