【发布时间】:2022-09-29 16:17:32
【问题描述】:
我正在尝试将带有包含单引号的字符串的行插入到 QuestDB 表中。我尝试使用以下代码以及使用控制台的以下 SQL 查询。两者都给了我同样的错误:\"\')\' expected\"。
插入到\'cpe_list\'(mystring)值(\'o\'\'brian\');
import psycopg2
connection = psycopg2.connect(user=\'someuser\', password=\'somepw\', host=\'127.0.0.1\', port=8812, database=\'mydb\')
cursor = connection.cursor()
cursor.execute(\"CREATE TABLE IF NOT EXISTS mytable (mystring STRING)\")
sql_query = \"INSERT INTO \'mytable\' (mystring) VALUES (%s);\"
cursor.execute(sql_query, (\"o\'brian\",))
Traceback (most recent call last):
File \"testSql.py\", line 9, in <module>
cursor.execute(sql_query, (\"o\'brian\",))
psycopg2.DatabaseError: \')\' expected
LINE 1: INSERT INTO \'mytable\' (mystring) VALUES (\'o\'\'brian\');
上面的代码是基于psycopg2 2.9.3关于查询参数的文档:https://www.psycopg.org/docs/usage.html?#the-problem-with-the-query-parameters
标签: python-3.x psycopg2 questdb