【发布时间】:2015-12-17 02:38:09
【问题描述】:
我正在尝试迁移一些将数据插入数据库的代码,以便继续使用 postgres。下面的代码/查询失败了,在查看了数组的大小之后,它似乎应该可以工作了。
任何关于失败原因的意见都会很棒。
我的 SQL 的样子:
sql = "insert into postgres.options.options (delta,gamma,rho,theta,\"impVol\",value,vega,date,ticker,\"callPut\",\"Chg\",\"maturity\",\"Symbol\",\"Strike\",\"Implied\",\"Last\",\"Vol\",\"Ask\",\"Bid\") values " \
"(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
我的数据看起来像这样:
data=[0.782154229511169, 0.026557152004256603, 0.005658995525391192, -0.4087164010990902, 136.71875, 8.94733166658628, 0.02387435675989819, 20150706, u'SVXY', u'C', -2.9, 20150710, u'SVXY150710C00070000', 70.0, 0.0, 7.9, 5.0, 9.2, 8.7]
我的python代码如下:
cur.execute(sql,data)
conn.commit()
我在桌子上的创建语句如下:
CREATE TABLE options.options
(
delta double precision,
gamma double precision,
rho double precision,
theta double precision,
"impVol" double precision,
value double precision,
vega double precision,
_id text,
date bigint,
ticker text,
"callPut" text,
"Chg" double precision,
maturity integer,
"Symbol" text,
"Strike" double precision,
"Implied" double precision,
"Last" double precision,
"Vol" double precision,
"Ask" double precision,
"Bid" double precision
)
我的错误是:
Traceback (most recent call last):
File "C:/Users/jasonmellone/PycharmProjects/price_options_multithread/migrate_error_options.py", line 41, in <module>
cur.execute(sql,data)
InternalError: current transaction is aborted, commands ignored until end of transaction block
【问题讨论】:
标签: python postgresql psycopg2