Re: Bytea and perl - Mailing list pgsql-novice

From Greg Sabino Mullane
Subject Re: Bytea and perl
Date
Msg-id a44a2dc421934081dccf4b50dc04001e@biglumber.com
Whole thread Raw
In response to Bytea and perl  (Sean Davis <sdavis2@mail.nih.gov>)
Responses Re: Bytea and perl  (Sean Davis <sdavis2@mail.nih.gov>)
List pgsql-novice
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


> What is the accepted way of inserting a binary string into
> a bytea column in perl?

It's pretty much as you described. Here's an example, modified
from the test suite:

use DBD::Pg qw(:pg_types);
...
my $sth = $dbh->prepare(qq{INSERT INTO dbd_pg_test (id,bytetest) VALUES (?,?)});

$sth->bind_param(2, undef, { pg_type => DBD::Pg::PG_BYTEA });

$sth->execute(400, 'aa\\bb\\cc\\\0dd\\');

Other options include storing just a filename, or base-64 encoding
everything and storing it as a text. I tend to prefer the latter
more often than not, as the encode/decode goes very quickly on
most modern computers.

- --
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200603222207
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----

iD8DBQFEIhEBvJuQZxSWSsgRAvAuAKDXEg6i+aykLuDeYpPCYCF+5XosNACfd/hZ
PR8cSm0/9NCJVInn+yEBpsU=
=jfTz
-----END PGP SIGNATURE-----



pgsql-novice by date:

Previous
From: Sean Davis
Date:
Subject: Bytea and perl
Next
From: Andrea
Date:
Subject: Problems using PostgreSQL command line tools