lo module
lo
module provides support for managing Large Objects (also called LOs or BLOBs). This includes a data type lo
and a trigger lo_manage
.Here's a simple example of usage:
CREATE TABLE image (title TEXT, raster lo);
CREATE TRIGGER t_raster BEFORE UPDATE OR DELETE ON image
FOR EACH ROW EXECUTE PROCEDURE lo_manage(raster);
For each column that will contain unique references to large objects, create a
BEFORE UPDATE OR DELETE
trigger,
and give the column name as the sole trigger argument. You can also
restrict the trigger to only execute on updates to the column by using BEFORE UPDATE OF
column_name
. If you need multiple lo
columns
in the same table, create a separate trigger for each one, remembering
to give a different name to each trigger on the same table.Limitations
- Dropping a table will still orphan any objects it contains, as the trigger is not executed. You can avoid this by preceding the
DROP TABLE
withDELETE FROM
.table
TRUNCATE
has the same hazard.If you already have, or suspect you have, orphaned large objects, see the vacuumlo module to help you clean them up. It's a good idea to run vacuumlo occasionally as a back-stop to thelo_manage
trigger. - Some front ends may create their own tables, and will not create the associated trigger(s). Also, users may not remember (or know) to create the triggers.
Comments
Post a Comment