Q:

PostgreSQL ERROR: trigger error when inserting new data

I created the following trigger, however when I try to insert some data in the table, the following error occurs: "control reached end of trigger procedure without RETURN".
I'm using the SQL Manager Lite for PostgreSQL version 5.9.5, I've tried changing the RETURN Null to RETURN NEW but when I try to compille, the same error occurs.
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;

The trigger is to calculate the comp time

A:

Any PostgreSQL function should be finished by RETURN statement.
Your code is not well formatted and it is not well readable
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;

After reformatting, you can see a path where the RETURN is missing.
I don't understand to your case, so I cannot to fix it, but for this code, I think so RETURN null can be only one as last statement of the trigger function.

