i have the following plpgsql function:
CREATE or replace TRIGGER conteo_nulls
AFTER INSERT OR UPDATE ON public.datos
FOR EACH ROW EXECUTE FUNCTION conteo_nulls();
create or replace function conteo_nulls() returns trigger as $$
declare
c INT;
rescrape bool := false;
feriado_ bool := false;
dia text;
begin
SELECT count(*) into c FROM public.datos where fundseries is null and scrap_date=new.scrap_date group by scrap_date;
if c > 5 then
rescrape := true;
end if;
dia := TO_CHAR(new.scrap_date, 'Day');
RAISE NOTICE 'El día de la semana es: %', pg_typeof(TO_CHAR(new.scrap_date::DATE, 'Day'));
**---THIS IF BLOCK NOT ENTER.
if dia::TEXT = 'Sunday' or dia::TEXT = 'Saturday'::TEXT then
RAISE NOTICE '****estoy dentro del if variable feriado es : %', feriado;
feriado_ := true;
end if;
--END BLOCK
**
RAISE NOTICE 'estoy fuera del if variable feriado es : %', feriado_;
insert into datos_resume values(new.scrap_date,c,rescrape,dia,feriado_);
RETURN NEW;
end;
$$
LANGUAGE plpgsql;
But on the second IF block, it not enter. Both text are ‘Sunday’, but the comparision not working. it is comparing “Sunday”=”Sunday” but it do not enter inside the if block and do not switch from false to true.
Could you helpme what i am doing wrong?
Thanks in advance.