lo_import

Started by Patrick Nelsonover 23 years ago3 messagesgeneral
Jump to latest
#1Patrick Nelson
pnelson@neatech.com

From a remote client what is the process of adding a blob (sa a image.jpg)
to the table. I'm not sure how to use the \lo_import and/or the lo_import
function in an insert call.

My table has a column of type OID. But I'm not sure if this is the proper
way either. What I'm interested in is how someone does these things:

1. Proper table column config
2. proper way of inserting into the table
3. proper way of exporting from the table
4. proper way of deleting

Please set me straight!

#2Cornelia Boenigk
poppcorn@cornelia-boenigk.de
In reply to: Patrick Nelson (#1)
Re: lo_import

Hi Patrick

docgen=# CREATE TABLE fotos (name CHAR(15), bild OID);
CREATE
docgen=# INSERT INTO fotos VALUES
docgen-# ('eule',lo_import('/home/conni/eule.gif'));
INSERT 18999 1
docgen=# SELECT * FROM fotos;
name | bild
-------------------+----------
eule | 18999
(1 row)

docgen=# SELECT lo_export(fotos.bild, '/tmp/euleout.gif')
docgen-# FROM fotos WHERE name = 'eule';
lo_export
-----------
1
(1 row)

docgen=# SELECT lo_unlink(fotos.bild) FROM fotos WHERE name = 'eule';
lo_unlink
-----------
1
(1 row)

Regards
Conni

#3Patrick Nelson
pnelson@neatech.com
In reply to: Cornelia Boenigk (#2)
Re: lo_import

Cornelia Boenigk wrote:
----------------->>>>
docgen=# CREATE TABLE fotos (name CHAR(15), bild OID);
CREATE
docgen=# INSERT INTO fotos VALUES
docgen-# ('eule',lo_import('/home/conni/eule.gif'));
INSERT 18999 1
docgen=# SELECT * FROM fotos;
name | bild
-------------------+----------
eule | 18999
(1 row)

docgen=# SELECT lo_export(fotos.bild, '/tmp/euleout.gif')
docgen-# FROM fotos WHERE name = 'eule';
lo_export
-----------
1
(1 row)

docgen=# SELECT lo_unlink(fotos.bild) FROM fotos WHERE name = 'eule';
lo_unlink
-----------
1
(1 row)
----------------->>>>

That works fine if your /home/conni/eule.gif is on the server, but what I
was wanting was the process to insert when your on a remote system and your
/home/conni/eule.gif is on the remote system not the server. You can use
the \lo_import <filename> to import a local file to the server, which then
can be seen with \lo_list and exported with \lo_export and then \lo_unlink
if you wish.

How do you put the OID into bild from the large objects list? I'm not sure
what the use of \lo_<cmd> is?