Re: Large Object to Bytea Conversion

From: Markus Schiltknecht <markus(at)bluegap(dot)ch>
To:
Cc: pgsql-general(at)postgresql(dot)org, Dimitri Fontaine <dim(at)dalibo(dot)com>
Subject: Re: Large Object to Bytea Conversion
Date: 2006-12-14 13:43:28
Message-ID: 45815500.8000609@bluegap.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message William Leite Araújo 2006-12-14 13:58:55 Re: A VIEW mimicing a TABLE
Previous Message Marc Evans 2006-12-14 12:58:45 8.2 server core dump