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