PostgreSQL ERROR: trigger error when inserting new data

PostgreSQL ERROR: trigger error when inserting new data

我创建了以下触发器,但是当我尝试在 table 中插入一些数据时,出现以下错误:"control reached end of trigger procedure without RETURN".

我正在使用 SQL Manager Lite for PostgreSQL 版本 5.9.5,我尝试将 RETURN Null 更改为 RETURN NEW 但是当我尝试编译,出现同样的错误。

BEGIN
    IF NEW.saida3 IS NOT NULL THEN
     UPDATE ponto
     SET banco_de_horas = "interval"((saida1 - entrada1) + (saida2 - entrada2) + (saida3 - entrada3) - '08:00:00')
     WHERE "time"(entrada1) < '22:00:00' AND "time"(entrada1) > '06:00:00' AND saida3 IS NOT NULL;
     RETURN NULL;
      ELSE IF NEW.saida2 IS NOT NULL THEN
       UPDATE ponto
       SET banco_de_horas = "interval"((saida1 - entrada1) + (saida2 - entrada2) - '08:00:00')
       WHERE "time"(entrada1) < '22:00:00' AND "time"(entrada1) > '06:00:00' AND saida2 IS NOT NULL;
       RETURN NULL;
     END IF;
   END IF;
END;

触发器是计算补偿时间

任何 PostgreSQL 函数都应由 RETURN 语句完成。

您的代码格式不正确,可读性差

BEGIN
  IF NEW.saida3 IS NOT NULL THEN
    UPDATE ponto
       SET banco_de_horas = "interval"((saida1 - entrada1) 
                            + (saida2 - entrada2) 
                            + (saida3 - entrada3) - '08:00:00')
      WHERE "time"(entrada1) < '22:00:00' 
        AND "time"(entrada1) > '06:00:00' 
        AND saida3 IS NOT NULL;
    RETURN NULL;
  ELSE 
    IF NEW.saida2 IS NOT NULL THEN
      UPDATE ponto
         SET banco_de_horas = "interval"((saida1 - entrada1) 
                            + (saida2 - entrada2) - '08:00:00')
       WHERE "time"(entrada1) < '22:00:00' 
         AND "time"(entrada1) > '06:00:00' 
         AND saida2 IS NOT NULL;
      RETURN NULL;
    END IF;
  END IF; --<<< THIS branch is not closed by RETURN
END;

重新格式化后,您可以看到缺少 RETURN 的路径。

我不明白你的情况,所以我无法修复它,但是对于这段代码,我认为 RETURN null 只能作为触发函数的最后一条语句。