You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support bytearray and memoryview as parameters #153
bytearray and memoryview objects cannot be used as parameters. In pg, they are converted with str() like objects of unknown types, so that values like "bytearray(b'abc')" or '<memory at 0x7f...>' are stored without an error, even in bytea columns and with inserttable(). pgdb raises an InterfaceError ("Do not know how to adapt type"), except for hstore values. In 6.3, pg will raise a TypeError and pgdb an InterfaceError in all these cases, so that no wrong data is stored.
psycopg 3 sends both types as bytea, like bytes. I plan to do the same in 6.4, with one rule everywhere: query parameters in pg and pgdb, also inline and as elements of arrays and records, inserttable() and escape_bytea(). memoryview objects that are not contiguous will be copied instead of rejected (psycopg 3 raises BufferError for them).
Open questions:
In the C layer, bytes parameters are passed unchanged as text in the client encoding. Should bytearray and memoryview always be sent as bytea there, or behave like bytes?
Should the data be copied, or the buffer held during the call?
Cursor.copy_from() should also be checked with such objects.
Activity