Problem with memoryview - Mailing list psycopg

From Frank Millman
Subject Problem with memoryview
Date
Msg-id C2C12FD0FCE64CE8BB77765A526D3C73@frank
Whole thread Raw
Responses Re: Problem with memoryview
List 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 by date:

Previous
From: Christophe Pettus
Date:
Subject: Re: Problem with the default registration of the JSON adapter
Next
From: Daniele Varrazzo
Date:
Subject: Re: Problem with memoryview