ERROR: only immutable functions supported in continuous aggregate view

2023-03-11 Thread Martijn de Munnik
t; = 'navigation.rateOfTurn')),     'first_time', public.first_time(public.time_weight('Linear', "time", "value"::double precision) FILTER (WHERE "path" = 'navigation.rateOfTurn')),     'first_val', public.first_val(public.time_weight('Linear', "time", "value"::double precision) FILTER (WHERE "path" = 'navigation.rateOfTurn')),     'last_time', public.last_time(public.time_weight('Linear', "time", "value"::double precision) FILTER (WHERE "path" = 'navigation.rateOfTurn')),     'last_val', public.last_val(public.time_weight('Linear', "time", "value"::double precision) FILTER (WHERE "path" = 'navigation.rateOfTurn'))   ) AS "navigation.rateOfTurn",   jsonb_build_object(     'max', max("value"::double precision) FILTER (WHERE "path" = 'navigation.speedOverGround'),     'min', min("value"::double precision) FILTER (WHERE "path" = 'navigation.speedOverGround'),     'mode', mode() WITHIN GROUP (ORDER BY "value") FILTER (WHERE "path" = 'navigation.speedOverGround' AND "value" IS NOT NULL),     'cardinality', COUNT(DISTINCT "value") FILTER (WHERE "path" = 'navigation.speedOverGround' AND "value" IS NOT NULL),     'average', public.average(public.time_weight('Linear', "time", "value"::double precision) FILTER (WHERE "path" = 'navigation.speedOverGround')),     'integral', public.average(public.time_weight('Linear', "time", "value"::double precision) FILTER (WHERE "path" = 'navigation.speedOverGround')) * EXTRACT(EPOCH FROM INTERVAL '5 min'),     'stddev', public.stddev(public.stats_agg("value"::double precision) FILTER (WHERE "path" = 'navigation.speedOverGround')),     'skewness', public.skewness(public.stats_agg("value"::double precision) FILTER (WHERE "path" = 'navigation.speedOverGround')),     'first_time', public.first_time(public.time_weight('Linear', "time", "value"::double precision) FILTER (WHERE "path" = 'navigation.speedOverGround')),     'first_val', public.first_val(public.time_weight('Linear', "time", "value"::double precision) FILTER (WHERE "path" = 'navigation.speedOverGround')),     'last_time', public.last_time(public.time_weight('Linear', "time", "value"::double precision) FILTER (WHERE "path" = 'navigation.speedOverGround')),     'last_val', public.last_val(public.time_weight('Linear', "time", "value"::double precision) FILTER (WHERE "path" = 'navigation.speedOverGround'))   ) AS "navigation.speedOverGround",   jsonb_build_object(     'mode', mode() WITHIN GROUP (ORDER BY "value") FILTER (WHERE "path" = 'navigation.state' AND "value" IS NOT NULL),     'cardinality', COUNT(DISTINCT "value") FILTER (WHERE "path" = 'navigation.state' AND "value" IS NOT NULL),     'first_time', public.first("time", "time") FILTER (WHERE "path" = 'navigation.state' AND "time" IS NOT NULL),     'first_val', public.first("value"#>>'{}', "time") FILTER (WHERE "path" = 'navigation.state' AND "time" IS NOT NULL),     'last_time', public.last("time", "time") FILTER (WHERE "path" = 'navigation.state' AND "time" IS NOT NULL),     'last_val', public.last("value"#>>'{}', "time") FILTER (WHERE "path" = 'navigation.state' AND "time" IS NOT NULL)   ) AS "navigation.state" FROM     "gosk"."mapped_data" WHERE     "path" IN (     'navigation.courseOverGroundTrue',     'navigation.datetime',     'navigation.gnss.methodQuality',     'navigation.gnss.satellites',     'navigation.gnss.type',     'navigation.headingTrue',     'navigation.position',     'navigation.rateOfTurn',     'navigation.speedOverGround',     'navigation.state'     ) GROUP BY     1, 2 WITH NO DATA; And that results in an error: ERROR:  only immutable functions supported in continuous aggregate view HINT:  Make sure all functions in the continuous aggregate definition have IMMUTABLE volatility. Note that functions or expressions may be IMMUTABLE for one data type, but STABLE or VOLATILE for another. The error is caused by the jsonb_build_object function, is there any reason why this function is not IMMUTABLE? I would have expected it to be IMMUTABLE. Kind regards, Martijn de Munnik

Re: ERROR: only immutable functions supported in continuous aggregate view

2023-03-12 Thread Martijn de Munnik
Ok, now I understand, thank you. My solution is to create materialized view with intermediate values and the create a normal view on top that uses the intermediate values and the jsonb_build_object function to create the desired result. Kind regards, Martijn de Munnik On 2023-03-11 16:47