Event Trigger Functions

PostgreSQL 9.4.5 Documentation
Prev | Up | Chapter 9. Functions and Operators | Next

# 9.28. Event Trigger Functions

Currently PostgreSQL provides one built-in event trigger helper function, `pg_event_trigger_dropped_objects`.

`pg_event_trigger_dropped_objects` returns a list of all objects dropped by the command in whose `sql_drop` event it is called. If called in any other context, `pg_event_trigger_dropped_objects` raises an error. `pg_event_trigger_dropped_objects` returns the following columns:

Name | Type | Description
--- | --- | ---
`classid` | `Oid` | OID of catalog the object belonged in
`objid` | `Oid` | OID the object had within the catalog
`objsubid` | `int32` | Object sub-id (e.g. attribute number for columns)
`object_type` | `text` | Type of the object
`schema_name` | `text` | Name of the schema the object belonged in, if any; otherwise `NULL`. No quoting is applied.
`object_name` | `text` | Name of the object, if the combination of schema and name can be used as a unique identifier for the object; otherwise `NULL`. No quoting is applied, and name is never schema-qualified.
`object_identity` | `text` | Text rendering of the object identity, schema-qualified. Each and every identifier present in the identity is quoted if necessary.

The `pg_event_trigger_dropped_objects` function can be used in an event trigger like this:

    CREATE FUNCTION test_event_trigger_for_drops()
            RETURNS event_trigger LANGUAGE plpgsql AS $$
    DECLARE
        obj record;
    BEGIN
        FOR obj IN SELECT * FROM pg_event_trigger_dropped_objects()
        LOOP
            RAISE NOTICE '% dropped object: % %.% %',
                         tg_tag,
                         obj.object_type,
                         obj.schema_name,
                         obj.object_name,
                         obj.object_identity;
        END LOOP;
    END
    $$;
    CREATE EVENT TRIGGER test_event_trigger_for_drops
       ON sql_drop
       EXECUTE PROCEDURE test_event_trigger_for_drops();

For more information about event triggers, see Chapter 37.

Prev | Home | Next
Trigger Functions | Up | Type Conversion