删除 table 会删除它的触发器和函数吗?

Does deleting a table delete its triggers as well as functions?

我创建了一个 table score 并且还创建了一个函数和一个触发器。

CREATE TABLE scores( 
--fields
);

CREATE FUNCTION scores_before_save() RETURNS trigger AS $$
BEGIN
   -- function logic
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER scores_before_save BEFORE INSERT OR UPDATE ON scores
    FOR EACH ROW EXECUTE PROCEDURE scores_before_save();

现在,我放弃了这个 table

DROP TABLE scores;

所以我的问题是触发器和函数是在我们删除 table 后自动删除的还是我们需要手动删除它们?

您可以轻松查看它们

-- check function existence
SELECT proname  FROM pg_proc WHERE proname    = 'scores_before_save';

-- check trigger existence
SELECT trigger_name from information_schema.triggers 
where trigger_name = 'scores_before_save';

如您所见,在删除 table 后,功能保留在这里,但触发器被删除。