with a AS (
    SELECT text '
160.1
129.7
84.8
120.1
160.1
124.9
84.8
116.9
169.7
140.9
89.7
123.3
187.3
144.1
92.9
120.1
176.1
147.3
89.7
123.3
185.7
155.3
99.3
131.3
200.1
161.7
102.5
136.1
204.9
176.1
112.1
140.9
227.3
195.3
115.3
142.5
244.9
214.5
118.5
153.7
244.9
216.1
188.9
142.5
301
196.9
136.1
267.3
317
230.5
152.1
336.2
371.4
240.1
158.5
355.4
449.9
286.6
179.3
403.4
491.5
321.8
177.7
409.8
593.9
329.8
176.1
483.5
584.3
395.4
187.3
485.1
669.2
421
216.1
509.1
827.7
467.5
209.7
542.7
840.5
414.6
217.7
670.8
848.5
437
209.7
701.2
925.3
443.4
214.5
683.6
917.3
515.5
224.1
694.8
989.4
477.1
233.7
730
1087
534.7
281.8
787.6
1163.9
613.1
347.4
782.8
    '
), b AS (
    SELECT id, val
    FROM a, unnest(string_to_array(
        regexp_replace(text, '((^\s+)|(\s+$))', '', 'g'), E'\n') :: float[])
        WITH ORDINALITY AS t (val, id)
), c AS (
    SELECT id, val,
        CASE WHEN count(val) over w = 12 THEN
            avg(val) over w
        END AS avg12
    FROM b
    WINDOW w AS (ORDER BY id ROWS 11 PRECEDING)
)
SELECT id, val, avg12,
    CASE WHEN count(avg12) over w = 12 THEN
        sqrt(sum(pow(val - avg12, 2)) over w / 12)
    END AS se
FROM c
WINDOW w AS (ORDER BY id ROWS 11 PRECEDING);
