Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #51641
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!xlned.com!feeder5.xlned.com!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.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'binary': 0.07; 'column': 0.07; 'postgresql': 0.07; 'integers': 0.09; 'present,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'strings.': 0.09; 'python': 0.11; 'wrote': 0.14; '*why*': 0.16; 'cleaner': 0.16; 'object)': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'storing': 0.16; 'str,': 0.16; 'subject:Problem': 0.16; 'solution.': 0.20; 'hack': 0.22; 'byte': 0.24; 'bytes': 0.24; 'comparing': 0.24; 'string,': 0.24; 'compare': 0.26; 'header:X-Complaints-To:1': 0.27; 'ideal': 0.29; 'xml': 0.29; 'returned': 0.30; "skip:' 10": 0.31; 'int,': 0.31; 'types.': 0.31; 'writes:': 0.31; 'anyone': 0.31; 'subject:with': 0.35; 'equal': 0.35; 'but': 0.35; 'add': 0.35; 'thanks': 0.36; 'server': 0.38; 'to:addr:python-list': 0.38; 'that,': 0.38; 'explain': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'range': 0.61; 'afraid': 0.65; 'frank': 0.68; 'results': 0.69; 'skip:n 40': 0.81; "'after'": 0.84; 'antoine.': 0.84; 'improvement': 0.84; 'cast': 0.91 |
| 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 | Wed, 31 Jul 2013 13:43:05 +0200 |
| References | <ktam8i$hj3$1@ger.gmane.org> <loom.20130731T114936-455@post.gmane.org> |
| X-Gmane-NNTP-Posting-Host | 197.87.30.34 |
| X-MSMail-Priority | Normal |
| X-Newsreader | Microsoft Outlook Express 6.00.3790.4657 |
| X-RFC2646 | Format=Flowed; Original |
| 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.10.1375270989.1251.python-list@python.org> (permalink) |
| Lines | 47 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1375270989 news.xs4all.nl 15998 [2001:888:2000:d::a6]:45608 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:51641 |
Show key headers only | View raw
"Antoine Pitrou" <solipsis@pitrou.net> wrote in message news:loom.20130731T114936-455@post.gmane.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. > Thanks for that, Antoine. It is an improvement over tobytes(), but i am afraid it is still not ideal for my purposes. At present, I loop over a range of columns, comparing 'before' and 'after' values, without worrying about their types. Strings are returned as str, integers are returned as int, etc. Now I will have to check the type of each column before deciding whether to cast to 'bytes'. Can anyone explain *why* the results do not compare equal? If I understood the problem, I might be able to find a workaround. Frank
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Problem with psycopg2, bytea, and memoryview "Frank Millman" <frank@chagford.com> - 2013-07-31 13:43 +0200
Re: Problem with psycopg2, bytea, and memoryview Neil Cerutti <neilc@norwich.edu> - 2013-07-31 14:08 +0000
Re: Problem with psycopg2, bytea, and memoryview "Frank Millman" <frank@chagford.com> - 2013-08-01 10:03 +0200
csiph-web