私はquestionを見ていて、バインド変数を使用しようと決めました。多くの時間差がないように思えるの上に私は、二組のために要した時間を見てみるとpostgresqlのバインド変数に関する質問
sql = 'insert into abc2 (interfield,textfield) values (%s,%s)'
a = time.time()
for i in range(10000):
#just a wrapper around cursor.execute
db.executeUpdateCommand(sql,(i,'test'))
db.commit()
と
sql = 'insert into abc2 (intfield,textfield) values (%(x)s,%(y)s)'
for i in range(10000):
db.executeUpdateCommand(sql,{'x':i,'y':'test'})
db.commit()
を使用しています。実際には、2番目の方法は時間がかかります。私がどこかでミスをした場合、誰かが私を正すことができますか?ここでpsycopg2を使用します。
@ Eir、私はpsycopg2でバインド変数は%(name)sのように指定されていると思いますか? – goh
私はこの形式のSQLで非常に注意を払い、実際には本番環境では使用しません。 –
少なくとも%(name)s –