Skip to content

Bit objects not supported with Psycopg 2 and pg8000 #169

Open

Description

@astroknot-sheep

Hi, pgvector.Bit works as a query parameter with Psycopg 3 (it registers a dumper), but not with Psycopg 2 or pg8000:

cur.execute('SELECT %s::bit(3)', (Bit('101'),))       # psycopg2: ProgrammingError: can't adapt type 'Bit'
conn.run('SELECT CAST(:b AS bit(3))', b=Bit('101'))   # pg8000: "i" is not a valid binary digit

Passing to_text() works, but it's inconsistent with Vector/HalfVector/SparseVector, which both drivers adapt. The pg8000 case is a bit worse since it sends the wrong value rather than raising a clear error.

For both drivers this is a small text adapter (same pattern as HalfvecAdapter / register_out_adapter); happy to open a PR if you'd like. (asyncpg left out on purpose, per #110.)

Tested with main (b5d9b70), Postgres 17, pgvector master.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions