psycopg,双引号和单引号插入
psycopg, double and single quotes insert
我 运行 在尝试插入数据库时遇到问题:
ur_psql.execute("""insert into smth(data, filedate, filedby)"""
""" values('%s', NOW(), %s)""" % (data, userid))
where data=""" "5.09,448,1418112000"; d="scan'208" """
(包含双引号和单引号的字符串)
任何想法如何将这样的字符串插入数据库?
谢谢
您可以在以下位置阅读:http://initd.org/psycopg/docs/usage.html#the-problem-with-the-query-parameters
不要在 SQL 中使用引号,而不是 %
字符串 Python 运算符使用 execute()
的第二个参数,这是您要传递给 SQL查询:
sql = "insert into smth (data, filedate, filedby) values (%s, NOW(), %s)"
ur_psql.execute(sql, (data, userid))
我 运行 在尝试插入数据库时遇到问题:
ur_psql.execute("""insert into smth(data, filedate, filedby)"""
""" values('%s', NOW(), %s)""" % (data, userid))
where data=""" "5.09,448,1418112000"; d="scan'208" """
(包含双引号和单引号的字符串)
任何想法如何将这样的字符串插入数据库?
谢谢
您可以在以下位置阅读:http://initd.org/psycopg/docs/usage.html#the-problem-with-the-query-parameters
不要在 SQL 中使用引号,而不是 %
字符串 Python 运算符使用 execute()
的第二个参数,这是您要传递给 SQL查询:
sql = "insert into smth (data, filedate, filedby) values (%s, NOW(), %s)"
ur_psql.execute(sql, (data, userid))