0
I’m new to the database and I could use a little help creating Rigger. I’m making a system where the user can open calls, I created a Rigger and need it to fire only when the type of call is occurrence (in the system, the types of calls are: occurrence, complaint, information, hazing, denunciation, praise, deception and interrupted connection).
The occurrence ID is 1.
CREATE OR REPLACE FUNCTION public.trigger_fct_tr_atend_tornozeleira()
 RETURNS trigger
 LANGUAGE plpgsql
 SECURITY DEFINER
AS $function$
declare
latitudeD float8;
longitudeD float8;
BEGIN
  BEGIN  
    BEGIN
    --descricao do estado para inserir na tabela de endereço
    SELECT latitude, longitude INTO STRICT latitudeD, longitudeD
    FROM endereco WHERE ID = NEW.id_endereco;
    EXCEPTION
      WHEN no_data_found THEN
      latitudeD = null, longitudeD = NULL;
    END;
    INSERT INTO atend_sac24(
                        id_atendimento,
                        data_criacao,
                        latitude,
                        longitude)
                VALUES (
                        NEW.id,
                        NEW.data_criacao,
                        latitudeD,
                        longitudeD);    
  END;
RETURN NEW;
END
$function$
;
						
And which field represents the occurrence?
– anonimo
Hi, sorry for the delay. I didn’t quite understand your question.
– RauzerFabiano