Search Postgresql Archives

Import file into bytea field in SQL/plpgsql?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux