postgre sql使用 %s时务必加引号,即为‘%s’,否则报错
if name == ‘main’:
t="TDD-LTE_MRO"
sql="select * from lastftp where enbid = %d and keytype = %s"%(110001,t)
print(selectOperate(sql))
结果:
Traceback (most recent call last):
File “/home/eyann/mypython/t1/pgSQLoperate.py”, line 84, in
print(selectOperate(sql))
File “/home/eyann/mypython/t1/pgSQLoperate.py”, line 45, in selectOperate
cursor.execute(sql)
psycopg2.ProgrammingError: column “tdd” does not exist
LINE 1: …* from lastftp where enbid = 110001 and keytype = TDD-LTE_MR…
^
if name == ‘main’:
t="TDD-LTE_MRO"
sql="select * from lastftp where enbid = %d and keytype = '%s'"%(110001,t)
print(selectOperate(sql))
结果:
[(‘test3’, ‘TDD-LTE_MRO’, ‘0114123000’, ‘0012’, 110001)]
[Finished in 0.1s]