timescale / timescaledb

An open-source time-series SQL database optimized for fast ingest and complex queries. Packaged as a PostgreSQL extension.
https://www.timescale.com/
Other
16.83k stars 852 forks source link

[Feature]: Allow Lateral Joins in CAGG Definitions #6959

Open ewoolsey opened 1 month ago

ewoolsey commented 1 month ago

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.

ewoolsey commented 1 month ago

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.