In PostgreSQL 9.3 I am trying to write a trigger function that will be called after updates to table test2
and that will delete rows of test2
where field "email" is empty. Here's my attempt:
CREATE OR REPLACE FUNCTION clean_emp() RETURNS trigger AS
$$
BEGIN
DELETE FROM test2 WHERE email=null;
return test2;
END;
$$
LANGUAGE plpgsql VOLATILE;
Then I set up the trigger like so:
CREATE TRIGGER trig_empty2
AFTER UPDATE OF name ON test2 FOR EACH ROW EXECUTE PROCEDURE clean_emp();
This gives me an error when I then do an update on table test2:
update test2 set name = name || 'fesgses';
ERROR: column "test2" does not exist
And here's my data table for completeness:
name | email
--------+-------------
hi | hiemail
shoe |
shoe2 |
cathy |
If anyone can give me some pointers on where I'm going wrong, I'd really appreciate it. Thank you.