timescale / timescaledb

An open-source time-series SQL database optimized for fast ingest and complex queries. Packaged as a PostgreSQL extension.

Home Page:https://www.timescale.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature]: Allow Lateral Joins in CAGG Definitions

ewoolsey opened this issue · comments

What problem does the new feature solve?

Here's an example query:

CREATE MATERIALIZED VIEW price
WITH (timescaledb.continuous) AS
select
	time, 
	(row ->> 'price_id') as "price_id",
	((row ->> 'price_state')::jsonb ->> 'price')::numeric as "price",
	(row ->> 'conf')::numeric as "conf"
from attribute, jsonb_array_elements(value::jsonb) as row
WHERE event_kind = 'injective.oracle.v1beta1.EventSetPythPrices'
GROUP BY (time_bucket('00:00:01'::interval, "time")), "time", attribute.value, row;

Essentially the goal is to destructure a json element into multiple rows. This seems to be a fairly common use case that isn't supported.

If there's a workaround I'm not aware of please let me know, but so far I have not been able to find a solution.