Import file into bytea field in SQL/plpgsql? - Mailing list pgsql-general

From Erwin Brandstetter
Subject Import file into bytea field in SQL/plpgsql?
Date
Msg-id 3617a52e-9930-49fd-a254-861b42ab847e@u69g2000hse.googlegroups.com
Whole thread Raw
Responses Re: Import file into bytea field in SQL/plpgsql?  (Richard Huxton <dev@archonet.com>)
List pgsql-general
Hi!

What I want to do:
Import a file from the file system into a bytea field of a table.

I know how to do it with large objects:
   INSERT INTO mytable(oid_fld) VALUES (lo_import('/mypath/myfile'));
And export from there:
   SELECT lo_export(oid_fld, '/mypath/myfile2') FROM mytable WHERE
<some condition>;

Now, I could copy over from pg_largeobject:
   INSERT INTO mytable(bytea_fld) SELECT data FROM pg_largeobject
WHERE loid = 1234567;
And create a large object and export from there as above.
But that seems unnecessarily complex, and  .. well .. stupid.

There must be a simpler way to import/export a file (as a whole, an
image for instance) into/out of my bytea field - in SQL or plpgsql?
Probably another set of functions I overlooked?


Thanks in advance
Erwin

pgsql-general by date:

Previous
From: "Luis Alberto Pérez Paz"
Date:
Subject: PGPOOL_HA
Next
From: Chris
Date:
Subject: Re: I don't understand this WARNING on pg_ctl startup