Re: Large Object to Bytea Conversion - Mailing list pgsql-general

From Markus Schiltknecht
Subject Re: Large Object to Bytea Conversion
Date
Msg-id 45815500.8000609@bluegap.ch
Whole thread Raw
In response to Re: Large Object to Bytea Conversion  (Markus Schiltknecht <markus@bluegap.ch>)
List pgsql-general
Hi,

I've sort of solved the problem for me. I'm now doing one single
lo_read() to fetch the bytea field. Those functions do not operate on
the large object OID, but one needs to open them first with lo_open().

I'm doing another hack to get the size of the large object.

All combined in a sql function (plpgsql is not installed...) looks like
that:

-- a helper function to convert large objects to bytea more efficiently
CREATE FUNCTION lo_readall(oid) RETURNS bytea
    AS $_$

SELECT loread(q3.fd, q3.filesize + q3.must_exec) FROM
    (SELECT q2.fd, q2.filesize, lo_lseek(q2.fd, 0, 0) AS must_exec FROM
        (SELECT q1.fd, lo_lseek(q1.fd, 0, 2) AS filesize FROM
            (SELECT lo_open($1, 262144) AS fd)
        AS q1)
    AS q2)
AS q3

$_$ LANGUAGE sql STRICT;


Does anybody know a better way? Why isn't a simple function like that
included? And is it just me or is the documentation lacking to describe
all the server side lo_* function? I've been studying the source to find
those.

Regards

Markus


pgsql-general by date:

Previous
From: Marc Evans
Date:
Subject: 8.2 server core dump
Next
From: Vlad
Date:
Subject: Re: creating an index with tablespace on a dedicated filesystem (postgresql 8.1.5)