Skip to content

Instantly share code, notes, and snippets.

@gurjeet
Created June 25, 2014 15:07
Show Gist options
  • Select an option

  • Save gurjeet/31c17ae70766f0de084f to your computer and use it in GitHub Desktop.

Select an option

Save gurjeet/31c17ae70766f0de084f to your computer and use it in GitHub Desktop.
PPAS bug: WARNING: unrecognized node type: 306
create table public.traffic_analysis(date_text text, load_avg_1_min double precision, hostname text not null, ts timestamp);
create type public.weekdays as enum (
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday'
);
with constants as (
select 6 as window_length, 'endb7pf'::text as hostname
)
select ts, load_avg_1_min, window_average, extract(week from ts), (enum_range(null::public.weekdays))[extract(dow from ts) + 1], row_number() over (partition by extract(week from ts) order by window_average) as rownum, window_average = min(window_average) over (partition by extract(week from ts)) as lowest
from(
select ts,
load_avg_1_min,
valid,
case when not valid then
null
else
avg(load_avg_1_min)
over (order by ts rows between current row and (select window_length-1 from constants) following)
end as window_average
from ( select ts,
load_avg_1_min,
(select window_length from constants)
= sum((load_avg_1_min is not null)::integer)
over (order by ts rows between current row and (select window_length-1 from constants) following) as valid
from public.traffic_analysis
where hostname = (select hostname from constants)) as v
) as v where rownum <=3 order by extract(week from ts), rownum;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment