Filter on time difference between current and next row
Consider the sequence of events in a SELECT query, as explained here:


Best way to get result count before LIMIT was applied


Window functions operate on the result set after WHERE clauses have been applied. It would be a logical contradiction to have a window functions in a WHERE clause. Like mustaccio said: use a subquery - or a CTE - to filter on the result of a window function.

But also get the logic right:


  where the time difference to the next row is greater than e.g. 10 seconds.


SELECT *
FROM  (
   SELECT created
        , lead(created) OVER (ORDER BY created) - created AS delta
   FROM   tbl
   ) t
WHERE  delta &gt; interval '10 sec'
ORDER  BY created;