Skip site navigation (1) Skip section navigation (2)

Re: Bytea and perl

From: "Greg Sabino Mullane" <greg(at)turnstep(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Bytea and perl
Date: 2006-03-23 03:08:02
Message-ID: a44a2dc421934081dccf4b50dc04001e@biglumber.com (view raw or flat)
Thread:
Lists: 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(at)turnstep(dot)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-----



Responses

pgsql-novice by date

Next:From: AndreaDate: 2006-03-23 11:44:41
Subject: Problems using PostgreSQL command line tools
Previous:From: Sean DavisDate: 2006-03-23 02:04:44
Subject: Bytea and perl

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group