I create a simple function and trigger to delete all rows from tb_users when a row from tb_city is deleted:
create or replace function delete_user()
returns trigger as
$$
begin
delete from rl_user_city where user_id in (select distinct user_id from rl_user_city where city_id = old.id) and city_id = old.id;
return new;
end;
$$
language plpgsql;
drop trigger if exists t_delete_user on tb_city;
create trigger t_delete_user
before delete on tb_city
for each row
execute procedure delete_user();
After I create this trigger, the command delete is not working: delete from tb_city where id = 385;
My tables:
tb_city:
id: int
city: string
tb_user_city:
user_id: int
city_id: int
I run, but the row is not deleted...
Any idea?