From: | "Frank Millman" <frank(at)chagford(dot)com> |
---|---|
To: | <psycopg(at)postgresql(dot)org> |
Subject: | Problem with memoryview |
Date: | 2013-07-31 14:08:09 |
Message-ID: | C2C12FD0FCE64CE8BB77765A526D3C73@frank |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Daniele Varrazzo | 2013-07-31 14:56:26 | Re: Problem with memoryview |
Previous Message | Christophe Pettus | 2013-07-22 16:13:53 | Re: Problem with the default registration of the JSON adapter |