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
17.91k stars 882 forks source link

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

Open 0xForerunner opened 5 months ago

0xForerunner commented 5 months 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.

0xForerunner commented 5 months 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.