[DB-SIG] Re: psycopg 0.96b1
Michele Comitini
mcm@initd.net
Thu, 30 Aug 2001 21:49:49 +0200
--z+pzSjdB7cqptWpS
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Hello Eric,
There are two simple ways to store DB-API 2.0 Binary objects in postgresql=
=20
>=3D 7.1. One is to store them in the text data type that requires
escaping in and unescaping out nulls. The other way is using the bytea
data type which is like text but is null safe exactly as a C char *=20
or a python String object. Using byteas allows to retrieve binary data
directly from the db using BINARY cursors, moreover unlike the lo_xxx
functions the bytea fields can be accessed like any other fields and
psycopg converts them to standard buffer objects with no fuzz.
Without the tedious record size limit which affected postgresql < 7.1 and
the variable sized text, bytea fields, capable of growing up to at least 2G=
b,
I see no much reason in using the lo_xxx functions besides backward
compatibility with postgresql < 7.1
For anyone interested a simple python example on how to store and
retrieve binary files in postgresql with and without the usage of an=20
SQL BINARY cursor is avalable in the examples dir in the psycopg
source distribution. Of course you can see how to access and put
data in bytea fields in the driver C source code.
You can get the psycopg driver a http://www.initd.org/Software/psycopg,
and remember that as I wrote erlier the code for binary objects
is quite new so please test it before using it in a production environment.
Thank you,
Michele Comitini
init.d http://www.initd.org
On Thu, Aug 30, 2001 at 12:09:41PM +0300, Eric Bianchi wrote:
> Hi,
>=20
> Concerning the binary objects support in Postgresql 7.1, It seems to me t=
hat bytea is a long text type and can't be considered as a binary object. B=
inary objects are handled by low level functions like lo_create, lo_open, .=
.. and their type is oid.=20
>=20
> According to Postgresql's documentation, bytea type must be considered as=
a text type.=20
>=20
> PoPy handles not quoted long text which is different than binary objects.
>=20
> Best Regards.
>=20
> --=20
> Eric Bianchi
>=20
>=20
>=20
--z+pzSjdB7cqptWpS
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE7jpjcHygWwn5gTsIRAg+IAJ92SH3vfCLe642cGlOSBBKUEgWJaQCfWyD5
qdpFsWDIDy5zeRi1DCNVLPg=
=qy8S
-----END PGP SIGNATURE-----
--z+pzSjdB7cqptWpS--