Database Reference
In-Depth Information
In case you have modified values in the TD["new"] and you want PostgreSQL to
continue with the new values, you can return MODIFY to indicate that you've modified
the new row. This can be done if TD["event"] is INSERT or UPDATE , otherwise
the return value is ignored.
Exploring the inputs of a trigger
The following trigger function is useful when developing triggers, so that you can
easily see what the trigger function is really getting when called:
CREATE OR REPLACE FUNCTION explore_trigger()
RETURNS TRIGGER
AS $$
import pprint
nice_data = pprint.pformat(
(
('TD["table_schema"]' , TD["table_schema"]
),
('TD["event"]' , TD["event"] ),
('TD["when"]' , TD["when"] ),
('TD["level"]' , TD["level"] ),
('TD["old"]' , TD["old"] ),
('TD["new"]' , TD["new"] ),
('TD["name"]' , TD["name"] ),
('TD["table_name"]' , TD["table_name"] ),
('TD["relid"]' , TD["relid"] ),
('TD["args"]' , TD["args"] ),
)
)
plpy.notice('explore_trigger:\n' + nice_data)
$$ LANGUAGE plpythonu;
This function formats all the data passed to the trigger in TD using
pprint.pformat , and then sends it to the client as a standard Python info mes-
sage using plpy.notify . For testing this out, we create a simple table and then
put an AFTER … FOR EACH ROW … trigger using this function on that table:
Search WWH ::




Custom Search