The test below shows that it is possible, but I am not verified performance (comparing for example with Bash or Python), and I don't understand exactly how to do or what happens:
- The lo_import/lo_get (in my
test_lo_proc
) created a copy of the file, or can it be used as (I supposed) an external reference? - Is it necessary to do
lo_unlink
? - The alternative, pg_read_binary_file as commented by @a_horse_with_no_name, is not limited in file size?
CREATE or replace FUNCTION test_lo_proc(
file_name text
) RETURNS text AS $f$
DECLARE
doc_oid oid;
md5 text;
BEGIN
doc_oid = lo_import(file_name);
md5 = md5(lo_get(doc_oid));
-- ? lo_unlink(doc_oid)
RETURN md5;
END;
$f$ LANGUAGE PLpgSQL;
SELECT test_lo_proc('/tmp/bigbigfile.zip');
PS: the MD5 is to compare performance (with md5sum *.zip
for example), real-life function use for example MD5(lo_content||metadata::bytea)
or something more complex using internal database resources... I am not looking for external execution (when you can use COPY t FROM PROGRAM
).