Python psycopg,双引号和单引号插入

Python psycopg,双引号和单引号插入,python,postgresql,psycopg2,Python,Postgresql,Psycopg2,我在尝试插入数据库时遇到问题: ur_psql.execute("""insert into smth(data, filedate, filedby)""" """ values('%s', NOW(), %s)""" % (data, userid)) 其中data=“””5.094481418112000;d=“scan'208”“(包含双引号和单引号的字符串) 你知道如何将这样的字符串插入数据库吗? 谢谢您可以在以下网址阅读有关内容: 不要在SQL中使用

我在尝试插入数据库时遇到问题:

ur_psql.execute("""insert into smth(data, filedate, filedby)"""
                """ values('%s', NOW(), %s)""" % (data, userid))
其中
data=“””5.094481418112000;d=“scan'208”“
(包含双引号和单引号的字符串) 你知道如何将这样的字符串插入数据库吗?
谢谢

您可以在以下网址阅读有关内容:

不要在SQL中使用引号,而是使用
execute()
的第二个参数来代替
%
字符串Python运算符,该参数是要传递给SQL查询的数据:

sql = "insert into smth (data, filedate, filedby) values (%s, NOW(), %s)"
ur_psql.execute(sql, (data, userid))

在同一查询中插入多个值/记录的模式应该是什么?无法找到简洁的解决方案。您可以在页面上的
executemany()
和字典示例中找到示例。