I have a table:
CREATE TABLE t_table (
c_id int4 NOT NULL,
c_date_called int4 NOT NULL,
CONSTRAINT t_table_un UNIQUE (c_id, c_date_called)
);
that stores distinct snapshots of data, with data as such:
INSERT INTO t_table (c_id, c_date_called)
VALUES
(1,9),
(2,9),
(3,9),
(4,9),
(5,9),
(1,12),
(2,12),
(3,12),
(5,12),
(1,17),
(3,17)
;
Against this table I can run an anti-join, comparing the current snapshot and one previous snapshot:
--EXPLAIN ANALYSE VERBOSE
SELECT prev.*
FROM t_table AS prev
LEFT JOIN t_table AS cur ON (prev.c_id = cur.c_id) AND cur.c_date_called = 17
WHERE prev.c_date_called = 9
AND cur.c_id IS NULL
;
returns the data I expect when finding the IDs not present in the current c_date_called:
c_id|c_date_called|
----+-------------+
2| 9|
4| 9|
But how do I apply the anti-join across multiple distinct c_date_called collecting the results and merging them as compared against the current c_date_called?
Well. Window functions with anti-joins.. yeah need help.

Well to report the complete state of the
iss in the snapshots, i.e. a snapshot with a newidnot present in the previous snapshot resp. theidremoved, i.e. not present in the next snapshot, you do not need an anti-join. Which you do not use in your example anyway.First define the sequence of the snapshots using integers and flag the current snapshot
Than join this supporting information to your main table and add two attribuites based on the
lagandleadwindow function of the snapshot index that identify if the previous / next snapshot with the givenidis consecutive or if there is a gap. The logic should be pretty self-explained.Note that I added
id6 that was introduced in the second snapshot to demonstrated this use case.