Advertisement
Guest User

Untitled

a guest
Jul 10th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE TABLE metrics(
  2. machine_id int NOT NULL,
  3. ts timestamptz NOT NULL,
  4. "V1_2" int NOT NULL,
  5. "V2_3" int NOT NULL,
  6. "V3_1" int NOT NULL
  7. );
  8.  
  9. INSERT INTO  metrics(machine_id, ts, "V1_2", "V2_3", "V3_1")
  10. SELECT n % 2 + 1, '20180711'::timestamptz + (n * interval '5 second'), n % 123, n % 438, n % 841
  11.   FROM generate_series(1, 100000) AS g(n);
  12.  
  13. CREATE INDEX ON metrics(machine_id, (date_trunc('day', ts AT TIME ZONE 'CEST')), ("V1_2" + "V2_3" + "V3_1"));
  14.  
  15. -- This could be used in LATERAL join to generated dates (generate_series):
  16. SELECT MAX ("V1_2" + "V2_3" + "V3_1") AS vmax,
  17.        MIN ("V1_2" + "V2_3" + "V3_1") AS vmin
  18.   FROM metrics AS m
  19.  WHERE m.machine_id = 1
  20.    AND date_trunc('day', ts AT TIME ZONE 'CEST') = '20180713';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement