Desea eliminar cualquier fila donde la fila anterior tenga el mismo tipo. Entonces:
select timestamp, type
from (select t.*,
lag(type) over (order by timestamp) as prev_type
from ticket_events t
) t
where prev_type <> type or prev_type is null;
El where
cláusula también se puede redactar como:
where prev_type is distinct from type
Si desea eliminar las filas "ofensivas", puede hacer lo siguiente, suponiendo que timestamp
es único:
delete from ticket_events
using (select t.*,
lag(type) over (order by timestamp) as prev_type
from ticket_events t
) tt
where tt.timestamp = t.timestamp and
tt.prev_type = t.type;