News for hackers. Stuff that matters.
Re:Function pipelines: Building functional programming into ... by EE84M3i on Tuesday October 19, 2021 @12:43PM (#28920211)
Note that your second example has a misplaced pair of parens:

    WITH temperature_delta_past_day AS
    (
        SELECT device_id, abs(val - lag(val) OVER (PARTITION BY device_id ORDER BY ts)) as abs_delta 
        FROM measurements
        WHERE ts >= now() - '1 day'::interval) calc_delta
    )
    SELECT device id, sum(abs_delta) as volatility
    FROM temperature_delta_past_day
    GROUP BY device_id;
should probably be

    WITH temperature_delta_past_day AS
    (
        SELECT device_id, abs(val - lag(val) OVER (PARTITION BY device_id ORDER BY ts)) as abs_delta 
        FROM measurements
        WHERE ts >= now() - '1 day'::interval
    )
    SELECT device id, sum(abs_delta) as volatility
    FROM temperature_delta_past_day
    GROUP BY device_id;
Re:Function pipelines: Building functional programming into ... by jpitz on Tuesday October 19, 2021 @01:02PM (#28920472)
You're correct - I was in a hurry to express the idea, and I failed to check the where clause.