0

I'm trying to improve my sql skills but I'm stuck on a syntax (I think!) error. I can't for the life of me figure out what's wrong! Any help is really appreciated :) thank you in advance!

with re_sample as (
    select resample_time(start_time, '5s') as resample_t, price from ftx_tick_trades
where
ticker = 'ETH-PERP'
and start_time > '2022-09-01'
and start_time < '2022-10-1'
limit 100
)

with recursive t as (
    (select resample_t, price from re_sample order by resample_t desc, price desc limit 1)
    union all
    select s.resample_t, s.price from t,
    lateral (
        select resample_t, price
        from re_sample
        where (re_sample.resample_t, re_sample.price) < (t.resample_t, t.price)
        order by resample_t desc, price desc
        limit 1
    ) s
) select * from t;

The error that pops up is

ERROR:  syntax error at or near "with"
LINE 22: with recursive t as (
         ^
SQL state: 42601
Character: 675

Lots of googling around.

0 Answers0