-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrwis.sql
More file actions
224 lines (214 loc) · 5.37 KB
/
rwis.sql
File metadata and controls
224 lines (214 loc) · 5.37 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
CREATE EXTENSION postgis;
-- Boilerplate IEM schema_manager_version, the version gets incremented each
-- time we make an upgrade script
CREATE TABLE iem_schema_manager_version(
version int,
updated timestamptz);
INSERT into iem_schema_manager_version values (9, now());
CREATE TABLE stations(
id varchar(64),
synop int,
name varchar(64),
state char(2),
country char(2),
elevation real,
network varchar(20),
online boolean,
params varchar(300),
county varchar(50),
plot_name varchar(64),
climate_site varchar(6),
remote_id int,
nwn_id int,
spri smallint,
wfo varchar(3),
archive_begin date,
archive_end date,
modified timestamp with time zone,
tzname varchar(32),
iemid SERIAL,
metasite boolean,
sigstage_low real,
sigstage_action real,
sigstage_bankfull real,
sigstage_flood real,
sigstage_moderate real,
sigstage_major real,
sigstage_record real,
ugc_county char(6),
ugc_zone char(6),
ncdc81 varchar(11),
ncei91 varchar(11),
temp24_hour smallint,
precip24_hour smallint,
wigos varchar(64),
geom geometry(POINT, 4326)
);
alter table stations owner to mesonet;
grant select on stations to ldm,nobody;
CREATE UNIQUE index stations_idx on stations(id, network);
create UNIQUE index stations_iemid_idx on stations(iemid);
CREATE TABLE sensors(
station varchar(5),
sensor0 varchar(100),
sensor1 varchar(100),
sensor2 varchar(100),
sensor3 varchar(100)
);
GRANT SELECT on sensors to nobody;
CREATE TABLE alldata(
station varchar(6),
valid timestamptz,
tmpf real,
dwpf real,
drct smallint,
sknt real,
tfs0 real,
tfs1 real,
tfs2 real,
tfs3 real,
subf real,
gust real,
tfs0_text text,
tfs1_text text,
tfs2_text text,
tfs3_text text,
pcpn real,
vsby real,
feel real,
relh real
) PARTITION by range(valid);
ALTER TABLE alldata OWNER to mesonet;
GRANT ALL on alldata to ldm;
GRANT SELECT on alldata to nobody;
CREATE TABLE alldata_traffic(
station char(5),
valid timestamp with time zone,
lane_id smallint,
avg_speed real,
avg_headway real,
normal_vol real,
long_vol real,
occupancy real
) PARTITION by range(valid);
ALTER TABLE alldata_traffic OWNER to mesonet;
GRANT ALL on alldata_traffic to ldm;
GRANT select on alldata_traffic to nobody;
CREATE TABLE alldata_soil(
station char(5),
valid timestamp with time zone,
tmpf_1in real,
tmpf_3in real,
tmpf_6in real,
tmpf_9in real,
tmpf_12in real,
tmpf_18in real,
tmpf_24in real,
tmpf_30in real,
tmpf_36in real,
tmpf_42in real,
tmpf_48in real,
tmpf_54in real,
tmpf_60in real,
tmpf_66in real,
tmpf_72in real
) PARTITION by range(valid);
ALTER TABLE alldata_soil OWNER to mesonet;
GRANT ALL on alldata_soil to ldm;
GRANT select on alldata_soil to nobody;
do
$do$
declare
year int;
mytable varchar;
begin
for year in 1994..2030
loop
mytable := format($f$t%s$f$, year);
execute format($f$
create table %s partition of alldata
for values from ('%s-01-01 00:00+00') to ('%s-01-01 00:00+00')
$f$, mytable, year, year + 1);
execute format($f$
ALTER TABLE %s OWNER to mesonet
$f$, mytable);
execute format($f$
GRANT ALL on %s to ldm
$f$, mytable);
execute format($f$
GRANT SELECT on %s to nobody
$f$, mytable);
-- Indices
execute format($f$
CREATE INDEX %s_station_idx on %s(station)
$f$, mytable, mytable);
execute format($f$
CREATE INDEX %s_valid_idx on %s(valid)
$f$, mytable, mytable);
end loop;
end;
$do$;
do
$do$
declare
year int;
mytable varchar;
begin
for year in 2008..2030
loop
mytable := format($f$t%s_traffic$f$, year);
execute format($f$
create table %s partition of alldata_traffic
for values from ('%s-01-01 00:00+00') to ('%s-01-01 00:00+00')
$f$, mytable, year, year + 1);
execute format($f$
ALTER TABLE %s OWNER to mesonet
$f$, mytable);
execute format($f$
GRANT ALL on %s to ldm
$f$, mytable);
execute format($f$
GRANT SELECT on %s to nobody
$f$, mytable);
-- Indices
execute format($f$
CREATE INDEX %s_station_idx on %s(station)
$f$, mytable, mytable);
execute format($f$
CREATE INDEX %s_valid_idx on %s(valid)
$f$, mytable, mytable);
end loop;
end;
$do$;
do
$do$
declare
year int;
mytable varchar;
begin
for year in 2008..2030
loop
mytable := format($f$t%s_soil$f$, year);
execute format($f$
create table %s partition of alldata_soil
for values from ('%s-01-01 00:00+00') to ('%s-01-01 00:00+00')
$f$, mytable, year, year + 1);
execute format($f$
ALTER TABLE %s OWNER to mesonet
$f$, mytable);
execute format($f$
GRANT ALL on %s to ldm
$f$, mytable);
execute format($f$
GRANT SELECT on %s to nobody
$f$, mytable);
-- Indices
execute format($f$
CREATE INDEX %s_station_idx on %s(station)
$f$, mytable, mytable);
execute format($f$
CREATE INDEX %s_valid_idx on %s(valid)
$f$, mytable, mytable);
end loop;
end;
$do$;