在 PLpgSQL 中使 "Create or replace" 起作用的不同方法

Different ways to make "Create or replace" function in PLpgSQL

我对数据库系统非常陌生,SQL,PLpgsql,postgresql 等。我正在学习创建和替换,我只能想到一种方法来实现创建和替换功能,例如:


RETURNS trigger AS $$
--Begins function
BEGIN

    perform phone, email from contact ;

if (new.phone) is null  OR (new.email) is null then RAISE EXCEPTION 'Bitte geben Sie mindestens eine der folgenden Informationen an: 1. Handy-Nummer 2. E-Mail Adresse' ;
END IF; 
Return new;
END;
$$

我怎样才能以不同的方式编写这个相同的函数,使其更短,这可能吗?如果可能的话,有人可以告诉我它是如何实现的,重写这个函数的可能方法吗?

PERFORM实际上是对完整的table执行顺序扫描,然后丢弃结果,完全没有必要,您应该将其删除。

NEW 会自动填充到 INSERT OR UPDATE 上的 FOR EACH ROW 触发器中,因此仅第二行就足够了。使用 BEFORE 触发器提高性能。