Database Reference
In-Depth Information
CREATE TABLE test(
id serial PRIMARY KEY,
data text,
ts timestamp DEFAULT clock_timestamp()
);
CREATE TRIGGER test_explore_trigger
AFTER INSERT OR UPDATE OR DELETE ON test
FOR EACH ROW
EXECUTE PROCEDURE explore_trigger('one', 2,
null);
Now, we can explore what the trigger function actually gets:
hannu=# INSERT INTO test(id,data) VALUES(1,
'firstrowdata');
NOTICE: explore_trigger:
(('TD["table_schema"]', 'public'),
('TD["event"]', 'INSERT'),
('TD["when"]', 'AFTER'),
('TD["level"]', 'ROW'),
('TD["old"]', None),
('TD["new"]',
{'data': 'firstrowdata', 'id': 1, 'ts':
'2013-05-13 12:04:03.676314'}),
('TD["name"]', 'test_explore_trigger'),
('TD["table_name"]', 'test'),
('TD["relid"]', '35163'),
('TD["args"]', ['one', '2', 'null']))
CONTEXT: PL/Python function "explore_trigger"
INSERT 0 1
Most of this is expected and corresponds well to the table of TD dictionary values
given in the previous table. What may be a little unexpected is the fact that the argu-
ments given in the CREATE TRIGGER statement are all converted to strings, even
the NULL . When developing your own triggers, either in PL/Python or any other lan-
guage, it may be useful to put this trigger on the table as well to check that the inputs
Search WWH ::




Custom Search