[Dbix-class] looking for some postgres bytea/lob pointers

Jesper Krogh jesper at krogh.cc
Fri Jun 9 09:31:07 CEST 2006

> Any suggestion about where I can find some examples
> would be appreciated.  I've already googled through the postgresql site an
> I checked over at the pgpdb
> mailing list.  I'm posting this here because I'd like to stay within the
> DBIx model if possible and was
> hoping someone else has already run into this issue.


I use BYTEA and have just dropped this "special" accessor in the Class:

sub file {
    my $self = shift;
	my $fref = shift;
	# set file.
	my $sth = $self->result_source->schema->storage->dbh->prepare("update
table set file = ? where id = ?");
	$sth->bind_param(1,$$fref, { pg_type => DBD::Pg::PG_BYTEA });
    my $f = $self->result_source->schema->storage->dbh->prepare("select
file from table where id = ?");
    my $hash = $f->fetchrow_hashref();
    return $hash->{file};

Note: It takes a scalar-ref as argument when setting the BYTEA,
remove one of the two $$-signs in order to set a regular scalar.

This can only be used on an existing object, but has the advantage of
beeing "lazy", meaning that you only fetch the actual column when needed.

Remember to put: "use DBD::Pg qw(:pg_types);" in the top of the file.

Otherwise, same as usual:

my $file = $rowobj->file();


Jesper Krogh

More information about the Dbix-class mailing list