2024-06-01 07:04:54 发布
网友
我在尝试插入数据库时遇到问题:
ur_psql.execute("""insert into smth(data, filedate, filedby)""" """ values('%s', NOW(), %s)""" % (data, userid))
其中data=""" "5.09,448,1418112000"; d="scan'208" """(包含双引号和单引号的字符串) 有什么办法把这样的字符串插入数据库吗? 谢谢
data=""" "5.09,448,1418112000"; d="scan'208" """
你可以在http://initd.org/psycopg/docs/usage.html#the-problem-with-the-query-parameters上阅读
只需在SQL中不要使用引号,而使用%string Python操作符,使用execute()的第二个参数,该参数是要传递给SQL query的数据:
%
execute()
sql = "insert into smth (data, filedate, filedby) values (%s, NOW(), %s)" ur_psql.execute(sql, (data, userid))
你可以在http://initd.org/psycopg/docs/usage.html#the-problem-with-the-query-parameters上阅读
只需在SQL中不要使用引号,而使用
%
string Python操作符,使用execute()
的第二个参数,该参数是要传递给SQL query的数据:相关问题 更多 >
编程相关推荐