开发者

Passing strings in value field in pyscopg2

开发者 https://www.devze.com 2023-01-06 02:06 出处:网络
Sorry this is a very newbie question.When I\'m trying to pass a tuple into an insert statement the quotations seem to disappear.

Sorry this is a very newbie question. When I'm trying to pass a tuple into an insert statement the quotations seem to disappear.

line=[0, 1, 3000248, 'G', 'T', 102, 102, 60, 25]
SNPinfo = tuple(line) 
curs.execute("""INSERT INTO akr (code, chrID, chrLOC, refBase, conBase, \
consqual, SNPqual, maxMapqual, numbR开发者_Python百科eadBases) \
VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s)""", SNPinfo) 

The Error I get is: LINE 1: ...axMapqual, numbReadBases) VALUES (0,1,3000248,G,T,102,10.. psycopg2.ProgrammingError: column "g" does not exist

I think my insert statement is wrong somewhere.


You are missing the single quotes around the varchars on your string formatting:

curs.execute("""INSERT INTO akr (code, chrID, chrLOC, refBase, conBase, \
consqual, SNPqual, maxMapqual, numbReadBases) \
VALUES (%s,%s,%s,'%s','%s',%s,%s,%s,%s)""", SNPinfo) 

This would produce:

INSERT INTO akr (code, chrID, chrLOC, refBase, conBase,
consqual, SNPqual, maxMapqual, numbReadBases) 
VALUES (0,1,3000248,'G','T',102,102,60,25)
0

精彩评论

暂无评论...
验证码 换一张
取 消