Problem with memoryview
| От | Frank Millman |
|---|---|
| Тема | Problem with memoryview |
| Дата | |
| Msg-id | C2C12FD0FCE64CE8BB77765A526D3C73@frank обсуждение исходный текст |
| Ответы |
Re: Problem with memoryview
|
| Список | psycopg |
Hi all
The following refers to Python 3.3.
I know that if you create a column of type 'bytea', psycopg2 accepts a
variety of inputs, but always returns a 'memoryview'.
I would like to know if it is possible, through some customisation option,
to tell it to return 'bytes'.
My problem is that, after a roundtrip to the database and back, the object
no longer compares equal to the original.
>>> memoryview(b'abcdef') == b'abcdef'
True
>>> cur.execute('create table fmtemp (code int, xml bytea)')
>>> cur.execute('insert into fmtemp values (%s, %s)', (1, b'abcdef'))
>>> cur.execute('select * from fmtemp where code =1')
>>> row = cur.fetchone()
>>> row
(1, <memory at 0xb725f77c>)
>>> row[1] == b'abcdef'
False
>>> row[1].tobytes() == b'abcdef'
True
>>>
TIA
Frank Millman
В списке psycopg по дате отправления: