Skip to content

Empty string is inserted as None when it's in the parameters in postgresql #3585

@CaselIT

Description

@CaselIT

What happened?

An empty string is inserted as null in postgresql when it's passed as a parameter

Stack Trace

Traceback (most recent call last):
  File "file.py", line 268, in <module>
    assert res == [('',), ('',)], res
           ^^^^^^^^^^^^^^^^^^^^^
AssertionError: [('',), (None,)]

How can we reproduce the bug?

from adbc_driver_postgresql.dbapi import connect
url = 'postgresql://scott:tiger@localhost/test' 
with connect(url) as conn:
    with conn.cursor() as cur:
        cur.execute('''CREATE TABLE text_table (text_data TEXT)''')
    with conn.cursor() as cur:
        cur.execute("INSERT INTO text_table VALUES ('')")
        cur.execute("INSERT INTO text_table VALUES ($1)", ('',))
    with conn.cursor() as cur:
        cur.execute("SELECT text_data FROM text_table")
        res = cur.fetchall()
        print(res)
        assert res == [('',), ('',)], res

the issue seems to be on the postgresql side, since trying the same code with sqlite works without errors

from adbc_driver_sqlite.dbapi import connect
with connect() as conn:
    with conn.cursor() as cur:
        cur.execute('''CREATE TABLE text_table (text_data TEXT)''')
    with conn.cursor() as cur:
        cur.execute("INSERT INTO text_table VALUES ('')")
        cur.execute("INSERT INTO text_table VALUES ($1)", ('',))
    with conn.cursor() as cur:
        cur.execute("SELECT text_data FROM text_table")
        res = cur.fetchall()
        print(res)
        assert res == [('',), ('',)], res

Environment/Setup

adbc_driver_manager = 1.8.0
adbc_driver_postgresql = 1.8.0

Metadata

Metadata

Labels

Type: bugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions