Re: Pyton buffer type vs psycopg2.Binary

Federico Di Gregorio <fog-NGVKUo/i/[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Organization initd.org
Message-ID <1251452291.4082.4.camel@mila>
Il giorno ven, 28/08/2009 alle 11.24 +0200, Oswaldo Hernández ha
scritto:
> Hello,
> 
> I just starting to work with bytea fields. I see the binary.py example that uses psycopg2.Binary to 
> covert the file data to bytea fields.
> 
> But making tests i discover that:
> 
> 1. When I read the bytea field psycopg2 returns the data as <type 'buffer'> instead psycopg2.Binary.

psycopg2.Binary is mandated by the DBAPI but it is not required to
create such objects when reading from the database. The correct round
trip supported by psycopg2 is buffer -> bytea -> buffer; i.e., you don't
need Binary at all.

> 2. psycopg2.Binary don't support __cmp__, then, if I try to compare two psycopg2.Binary objects is 
> always False bacause the comparison is made with the objects id() instead the objects data.

Use buffers.

> 3. In the tests i try to save de data using 'buffer(open(file, "rb").read())' instead of 
> 'psycopg2.Binary(open(file, "rb").read())' and, at this moment, it works fine.
> 
> The question is:
> 
> Is there any disadvantage or any other problem if i use the buffer type instead psycopg2.Binary?

No problem, you're right.

federico

-- 
Federico Di Gregorio                         http://people.initd.org/fog
Debian GNU/Linux Developer                                [email protected]
INIT.D Developer                                           fog-NGVKUo/i/[email protected]
 Degli altri, della gente senza domande, si puo' fare a meno.
                                                       -- macchinavapore

_______________________________________________
Psycopg mailing list
Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/psycopg
signature.asc (application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEABECAAYFAkqXpYMACgkQvcCgrgZGjevvKQCcDmBtFeq2NJe2pOQ3fxRraSa6
yX4AoJ8tKzd/GnB5lxn4rMTgOfJiF/ko
=tBjR
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.