Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #51784

Re: Problem with psycopg2, bytea, and memoryview

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'example:': 0.03; 'resulting': 0.04; 'binary': 0.07; 'postgresql': 0.07; 'string': 0.09; 'imho.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'suggest': 0.14; 'wrote': 0.14; '"terry': 0.16; '9.0': 0.16; 'adapter': 0.16; 'agree.': 0.16; 'antoine': 0.16; 'bytes).': 0.16; 'choice,': 0.16; 'parser.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'record,': 0.16; 'reedy"': 0.16; 'subject:Problem': 0.16; 'wrote:': 0.18; 'later': 0.20; '(the': 0.22; '(in': 0.22; 'preferred': 0.22; 'bytes': 0.24; 'requirement.': 0.24; 'pass': 0.26; 'asking': 0.27; 'header:X -Complaints-To:1': 0.27; 'function': 0.29; 'feature': 0.29; 'am,': 0.29; "doesn't": 0.30; 'code': 0.31; 'breaking': 0.31; 'consequence': 0.31; 'object.': 0.31; 'handled': 0.32; '(e.g.': 0.33; 'sense': 0.34; 'received:co.za': 0.34; 'received:za': 0.34; 'subject:with': 0.35; 'created': 0.35; 'case,': 0.35; 'objects': 0.35; 'but': 0.35; 'there': 0.35; 'version': 0.36; 'really': 0.36; 'returning': 0.36; 'list': 0.37; 'project': 0.37; 'thank': 0.38; 'needed': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'forwarded': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'ago,': 0.61; 'break': 0.61; 'new': 0.61; 'our': 0.64; 'reply': 0.66; 'frank': 0.68; 'default': 0.69; 'received:41': 0.70; 'obvious': 0.74; 'gain': 0.79; 'widespread': 0.91; 'anymore,': 0.95
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From "Frank Millman" <frank@chagford.com>
Subject Re: Problem with psycopg2, bytea, and memoryview
Date Fri, 2 Aug 2013 08:23:01 +0200
References <ktam8i$hj3$1@ger.gmane.org><loom.20130731T114936-455@post.gmane.org><ktat7p$t70$1@ger.gmane.org><loom.20130731T150154-520@post.gmane.org> <ktbj9i$4au$1@ger.gmane.org>
X-Gmane-NNTP-Posting-Host 41-135-111-146.dsl.mweb.co.za
X-MSMail-Priority Normal
X-Newsreader Microsoft Outlook Express 6.00.3790.4657
X-RFC2646 Format=Flowed; Response
X-MimeOLE Produced By Microsoft MimeOLE V6.00.3790.4913
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.107.1375424598.1251.python-list@python.org> (permalink)
Lines 45
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1375424598 news.xs4all.nl 15961 [2001:888:2000:d::a6]:57275
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:51784

Show key headers only | View raw


"Terry Reedy" <tjreedy@udel.edu> wrote in message 
news:ktbj9i$4au$1@ger.gmane.org...
> On 7/31/2013 9:07 AM, Antoine Pitrou wrote:
>>
>> I would suggest asking the psycopg2 project why they made this choice, 
>> and
>> if they would reconsider. Returning a memoryview doesn't make much sense 
>> IMHO.
>
> I agree.
> "memoryview objects allow Python code to access the internal data of an 
> object that supports the buffer protocol without copying."
> Example: the binary image data of an image object.
> They are not intended to be a standalone objects when there is an obvious 
> alternative (in this case, bytes).

For the record, I forwarded this to the psycopg2 list, and got the following 
reply from Daniele Varrazzo -

<reply>
Hi Frank, thank you for forwarding the thread.

Until a not very long time ago, this was exactly the case: upon
reading bytea we were handed over some data to pass to a libpq
function to decode. The resulting decoded string was to be released by
PQfreemem, and the memoryview was the right object to reconcile the
lifetime of the python object with this deallocation requirement.
Later things have changed: because of the change in bytea format in
PostgreSQL 9.0 (the new format was the default and wasn't handled by
libpq < 9.0, which created widespread problems) we wrote our own
parser. As a consequence the memoryview is not really needed anymore,
but we preferred to avoid breaking programs already using the current
interface.

So yes: bytes (and str on Py2) is definitely a better object to get in
Python. It is already on the list of what I want in a version that
would break compatibility in order to gain feature or improve the
adapter in other ways (e.g. psycopg3).
</reply>

Frank


Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Problem with psycopg2, bytea, and memoryview "Frank Millman" <frank@chagford.com> - 2013-08-02 08:23 +0200

csiph-web