Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #51636 > unrolled thread
| Started by | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| First post | 2013-07-31 09:50 +0000 |
| Last post | 2013-07-31 09:50 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Problem with psycopg2, bytea, and memoryview Antoine Pitrou <solipsis@pitrou.net> - 2013-07-31 09:50 +0000
| From | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| Date | 2013-07-31 09:50 +0000 |
| Subject | Re: Problem with psycopg2, bytea, and memoryview |
| Message-ID | <mailman.5.1375264264.1251.python-list@python.org> |
Frank Millman <frank <at> chagford.com> writes: > > I have some binary data (a gzipped xml object) that I want to store in a > database. For PostgreSQL I use a column with datatype 'bytea', which is > their recommended way of storing binary strings. > > I use psycopg2 to access the database. It returns binary data in the form of > a python 'memoryview'. > [...] > > Using MS SQL Server and pyodbc, it returns a byte string, not a memoryview, > and it does compare equal with the original. > > I can hack my program to use tobytes(), but it would add complication, and > it would be database-specific. I would prefer a cleaner solution. Just cast the result to bytes (`bytes(row[1])`). It will work both with bytes and memoryview objcts. Regards Antoine.
Back to top | Article view | comp.lang.python
csiph-web