I have a problem to perform a search for numerical sequence break in postgresql, I need that, for example, if my seq column is out of sequence I will be notified by email, for example my sequence is: 340,341,342
if it is: 340 342,343
this with a sequence failure.
CodePudding user response:
You can use next query to find anomalies:
select count(*) from (
select id - (lag(id) over (order by id)) diff from tbl
) t where diff is not null and diff <> 1;
When result of the query not 0 anomaly found