Re: Import file into bytea field in SQL/plpgsql?

From: Richard Huxton <dev(at)archonet(dot)com>
To: Erwin Brandstetter <brsaweda(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Import file into bytea field in SQL/plpgsql?
Date: 2008-03-05 09:20:38
Message-ID: 47CE65E6.904@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Emmanuel Quevillon 2008-03-05 09:43:53 Terminal completion
Previous Message Richard Huxton 2008-03-05 09:09:47 Re: Meaning og Logs