QuestDB and psycopg3 server-side parameter binding

30 Views Asked by At

I'm developing a python application with QuestDB 7.3.7 and psycopg 3.2, and I have run into an issue with SELECT queries returning weird results when using WHERE clauses with parameter binding.

Consider the following example:

# imports and constants definitions omitted

with psycopg.connect(
    DB_URL, password=PASS, autocommit=True#, cursor_factory=ClientCursor
) as conn:
    with conn.cursor() as cur:
        cur.execute("""
            DROP TABLE IF EXISTS test;
            CREATE TABLE test (
                chat_id SYMBOL CAPACITY 32768,
                title STRING
            ), INDEX (chat_id);
            """)

        cur.execute("INSERT INTO test (chat_id, title) VALUES (%s, %s)",
            ("-1001410861641", "Levitov Chess"))

    def get_chat(chat_id):
        with conn.cursor() as cur:
            sql = "SELECT * FROM test WHERE chat_id = %s;"
            cur.execute(sql, (str(chat_id),))
            return cur.fetchone()

    print(get_chat(-1001410861641))
    print(get_chat(-1001211727369))

I get the following output when running this code:

('-1001410861641', 'Levitov Chess')
('-1001410861641', 'Levitov Chess')

I'm expecting the second query to return None. If I uncomment the cursor_factory line in the call to connect method, which makes psycopg use client-side binding, I get the expected output:

('-1001410861641', 'Levitov Chess')
None

Is this is a known limitation or could this be considered a bug in QuestDB?

0

There are 0 best solutions below