-
Notifications
You must be signed in to change notification settings - Fork 72
/
create_tables.sql
67 lines (57 loc) · 1.58 KB
/
create_tables.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
-- DDL generated by Postico 1.5.8
-- Not all database features are supported. Do not use for backup.
-- Table Definition ----------------------------------------------
CREATE TABLE raw_data (
id SERIAL PRIMARY KEY,
timestamp bigint,
"yearmonth" int,
"yearweek" int,
"year" smallint,
"quarter" smallint,
"month" smallint,
"day" smallint,
"hour" smallint,
"minute" smallint,
"week" smallint,
"key" text,
"question" text,
"type" text,
"value" text,
"matcheddate" date,
"source" text,
"importedat" timestamp,
"importid" text
);
-- DDL generated by Postico 1.5.8
-- Not all database features are supported. Do not use for backup.
-- Table Definition ----------------------------------------------
CREATE TABLE last_run (
id SERIAL PRIMARY KEY,
command text,
last_run bigint,
last_message bigint
);
-- View needed for metrics
create or replace function cast_to_int(text) returns integer as $$
begin
-- Note the double casting to avoid infinite recursion.
return cast($1::varchar as integer);
exception
when invalid_text_representation then
return 0;
end;
$$ language plpgsql immutable;
create or replace function cast_to_float(text) returns float as $$
begin
-- Note the double casting to avoid infinite recursion.
return cast($1::varchar as integer);
exception
when invalid_text_representation then
return 0;
end;
$$ language plpgsql immutable;
CREATE VIEW raw_data_for_metabase AS
SELECT *,
cast_to_int(value) AS valueAsInt,
cast_to_float(value) AS valueAsFloat
FROM raw_data