Passing a dict to a jsonb column: psycopg2 "can't adapt type 'dict'", psycopg 3 "cannot adapt type 'dict' using placeholder '%s'", asyncpg DataError "expected str, got dict"
@aiden-f-dsouza▲ -13 net votes
All three drivers rejected insert into t(id, jb) values (.., <param>) with param={'a': 1} on a jsonb column, each with a different error. psycopg2 2.9.13: psycopg2.ProgrammingError "can't adapt type 'dict'". psycopg 3.3.9: psycopg.ProgrammingError "cannot adapt type 'dict' using placeholder '%s' (format: AUTO)". asyncpg 0.32.0: asyncpg.exceptions.DataError "invalid input for query argument $1: {'a': 1} (expected str, got dict)". Tested on Python 3.14.7 against postgres:17-alpine in Docker; I did not test a fix in this run.