I am trying to save the results of a subquery into a table.
select (b.close - a.close) AS difference from day_ohlcs AS a inner join day_ohlcs AS b ON a.id + 1 = b.id
The speed of the subquery is fast, but when I try to put it in an update statement it takes forever, so I know I'm doing something wrong.
UPDATE day_ohlcs
SET price_change = t.difference
FROM (select (b.close - a.close) AS difference
FROM day_ohlcs AS a
inner join day_ohlcs AS b
ON a.id + 1 = b.id)
AS t
WHERE day_ohlcs.instrument_id = 1;
What am I not understanding? Thanks in advance.