Mary Christie Generalao wrote:
> 
> hi pluggers,
> I've seen several postgres-related posts before, so I
> presume there are some postgres users here. Can you
> possibly give me an idea how to store binary data in a
> postgres table? I found out postgres doesnt have the
> BLOB data type of oracle. Any hints? As this is
> off-topic, I'd appreciate responses sent privately.

It's more on-topic than a lot of posts.

Postgres can store large objects and refer to them via their oid. For
the SQL interface, there is a function lo_import which will take a file
and import it into the DB. It returns the Oid. Clearly you should store
the Oids in your own tables. There's also a lo_export function. 

The example from the PG7 documentation is quite clear as to how these
are used:

CREATE TABLE image (
    name            text,
    raster          oid
);

INSERT INTO image (name, raster)
    VALUES ('beautiful image', lo_import('/etc/motd'));

SELECT lo_export(image.raster, '/tmp/motd') from image
    WHERE name = 'beautiful image';

Also, the psql monitor also provides \lo_import, \lo_export, \lo_list
and \lo_unlink. Very useful.

Of course these just use the C API functions lo_import(), lo_open() etc.

HTH
Brian
_
Philippine Linux Users Group. Web site and archives at http://plug.linux.org.ph
To leave: send "unsubscribe" in the body to [EMAIL PROTECTED]

To subscribe to the Linux Newbies' List: send "subscribe" in the body to 
[EMAIL PROTECTED]

Reply via email to