【问题标题】:Escaping single quote in questDB using Python3使用 Python3 在 questDB 中转义单引号
【发布时间】: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


    【解决方案1】:

    我验证了它,这似乎是一个错误。我创建了一个issue on Github to track it

    同时,您始终可以使用 ILP 协议(​​Python 示例可在the QuestDB docs 获得)

    还有一个即将发布的 QuestDB 官方 Python 客户端,它应该会使 ILP 摄取更加方便,但仍有待发布。

    【讨论】:

      【解决方案2】:

      刚刚说 QuestDB 刚刚发布了一个新版本,其中包含修复 https://github.com/questdb/questdb/releases/tag/6.5.3

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-27
        • 2012-07-25
        • 2019-03-29
        • 1970-01-01
        • 2019-11-29
        • 2015-01-10
        • 2012-07-18
        • 2011-10-04
        相关资源
        最近更新 更多