Adam Seering wrote:
> Thanks for the link; still trying to figure out how to use these
> functions, though.
> The link that you sent suggests that these commands are really only
> useful for writing out data to server-side files, which isn't so much
> what I want. What I really want is to lo_open a file, then lo_lseek
to
> a particular address and loread a constant number of bytes (to be
> returned as the query result), then lo_close the file.
Out of curiosity, I've just quickly tried this:
CREATE OR REPLACE FUNCTION lo_part(oid,integer,integer) RETURNS bytea
AS $$
declare
fd integer;
c bytea;
i integer;
begin
fd = lo_open($1, 262144); -- INV_READ
i=lo_lseek(fd,$2,0); --arg 2 is offset
c = loread(fd, $3); -- arg 3 is size
i=lo_close(fd);
return c;
end;
$$ LANGUAGE 'plpgsql';
...and it appears to work, isn't it what you say you need?
> I'm currently stuck on the easy part: lo_open always returns 0,
which
> gives me "ERROR: invalid large-object descriptor: 0" when I try to
use
> it with loread.
Generally it's because you've forgotten to start a transaction. lo_*
functions need to be executed inside a transaction, otherwise you get
that error (the message is not exactly helpful in this particular case,
admittedly!)
Best regards,
--
Daniel
PostgreSQL-powered mail user agent and storage:
http://www.manitou-mail.org