<span style="font-family: Arial, Helvetica, sans-serif;">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" class="python">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