- Symptom
- psycopg.errors.SyntaxError: syntax error at or near "$1"psycopg.errors.SyntaxError: cannot insert multiple commands into a prepared statement
- Cause
- psycopg 3 sends parameters to the server separately, and PostgreSQL accepts them only in plain SELECT and data change statements, one statement per call. psycopg2 merged values into the text on the client, so both patterns used to work.
- Fix
- Use the function forms set_config and pg_notify, split multi-statement strings into separate execute calls, or use ClientCursor for client-side binding.
- Apply
conn.execute("SELECT set_config('TimeZone', %s, false)", ["UTC"]) conn.execute("SELECT pg_notify(%s, %s)", ["chan", "42"])- Affected
- psycopg 3.x, when porting code from psycopg2
- Sources
Last verified 2026-10-15 · Confirmed by 0 builders