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

From Richard Huxton
Subject Re: Import file into bytea field in SQL/plpgsql?
Date
Msg-id 47CE65E6.904@archonet.com
Whole thread Raw
In response to Import file into bytea field in SQL/plpgsql?  (Erwin Brandstetter <brsaweda@gmail.com>)
List pgsql-general
Erwin Brandstetter wrote:
> Hi!
>
> What I want to do:
> Import a file from the file system into a bytea field of a table.

> Now, I could copy over from pg_largeobject:

> 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?

Not that I know of. It's simple enough to do from the application side
of things of course (well, in most languages) but there's no general
file access.

You can do various tricks to grab text values (see psql in the docs "SQL
Interpolation") but you'd need to escape the values. Not sure that's any
cleaner than the large-object approach.

--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Meaning og Logs
Next
From: Emmanuel Quevillon
Date:
Subject: Terminal completion