I didn't know the answer to your question so I checked in the usual places. I'm mostly telling you story of how I got the information I'm about to share since you'll need to be able to do this later on your own.

I first checked the mailing list archives on postgresql.org (which appear to be down right now) and the google query postgresql bytea perl which returns the wonderful post Re: Escaping Binary Data in DBD::Pg. So this leads me back to DBI and it's support of data types. Reading that yields the nifty snippet perl -MDBI=:sql_types -e 'for(@{$DBI::EXPORT_TAGS{sql_types}}){printf "%s=%d\n", $_, &{"DBI::$_"}}'|grep BINARY. That also mentions to check out type_info(), type_info_all() and bind_param() for possible uses of that information.

All that work (15 minutes actually) brings me to the following potential code snippet. If this doesn't work then follow up with that archive message I linked to. The PostgreSQL mailing list is also a good place to ask this sort of question.

use DBI qw(:sql_types); # ... my $sth = $dbh->prepare("insert into demo values (?, ?)"); $sth->bind_param( 1, 'test', SQL_TEXT ); $sth->bind_param( 2, nfreeze($test), SQL_BINARY ); $sth->execute;
__SIG__ use B; printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B::svref_2object(sub{})->OUTSIDE;

In reply to Re: postgresql: store binary data? by diotalevi
in thread postgresql: store binary data? by ph0enix

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.