I am trying to create a timeseries and a lag of it at the same time using lateral:
dates as (
SELECT generate_series(max(timestamp), min(timestamp), '1 week'::interval) as ts
FROM batches,
LATERAL (SELECT lag(ts) over (order by ts)) as prev_ts
),
For some reason I get ERROR: column "ts" does not exist
. What is going on?