select * from pbx_classifica_reg where data_reg::date = now()::date and id_dac is null select * from pbx_classifica_reg where id_dac is null begin update pbx_classifica_reg set id_dac = (select id from pbx_dacs where nome = b.fila) from pbx_classifica_reg a, pbx_eventos_dacs b where b.uid2 = a.id_bilhetes and a.id_dac is null and b.evento = 'CONNECT' commit rollback update pbx_classifica_reg set contrib_id = null where id_dac is null select * from pbx_classifica_reg where id_bilhetes in (select uid2 from pbx_eventos_dacs) delete from pbx_classifica_reg where id_bilhetes not in (select uid2 from pbx_eventos_dacs) update pbx_classifica_reg