zl程序教程

您现在的位置是:首页 >  其他

当前栏目

postgre 执行execute参数为元组详解程序员

执行程序员 详解 参数 execute 元组 postgre
2023-06-13 09:20:21 时间
 span sql = "select title,content,nid from newslist_v2 where nid in (%s)"
conn, cursor = get_postgredb() 

cursor.execute(sql, [ads_str])

报错:

    psycopg2.DataError: invalid input syntax for integer: .LINE 1: title,content,nid from newslist_v2 where nid in ( (5663445,..

2. 

 

 pre name="code" sql = "select title,content,nid from newslist_v2 where nid in (%s)" 

conn, cursor = get_postgredb() 

cursor.execute(sql, (ads_str))



     或

   

sql = "select title,content,nid from newslist_v2 where nid in (%s)" 

conn, cursor = get_postgredb() 

cursor.execute(sql, ads_str)

报错:

       TypeError: not all arguments converted during string formatting

3. ok的方法:

     

sql = "select title,content,nid from newslist_v2 where nid in {0}" 

conn, cursor = get_postgredb() 

cursor.execute(sql.format(ads_str))

     

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/7438.html

服务器部署程序员系统优化网站设置运维