comparison database/schema/classify.sql @ 29:cd36b49f4437

fix. now loads into postgresql92
author David A. Holland
date Sun, 26 May 2013 23:24:45 -0400
parents ca4679ac4e02
children 40f64a96481f
comparison
equal deleted inserted replaced
28:000519947282 29:cd36b49f4437
124 pr bigint not null references PRs (id), 124 pr bigint not null references PRs (id),
125 scheme text not null references hierclass_names (name), 125 scheme text not null references hierclass_names (name),
126 value text , 126 value text ,
127 primary key (pr, scheme), 127 primary key (pr, scheme),
128 -- 128 --
129 -- what I want here is for it to reference hierclass_values unless 129 -- Ok, the intended semantics here are:
130 -- the value is null. or should the values table include a row 130 -- * For PRs that the classification doesn't apply to, there
131 -- with null value where that's allowed? I forget how null values 131 -- should be no row at all in the *class_data table.
132 -- interoperate with reference constraints except that it's messy. 132 -- * For PRs where the classification is undetermined or
133 -- XXX. (if changing this change the similar logic below as well) 133 -- unassigned, the value column should be null, and if
134 -- that's allowed there should be a null entry in
135 -- the *class_values table.
136 -- I believe "MATCH SIMPLE" to be capable of enforcing this,
137 -- but that's from reading postgres docs and not from actually
138 -- checking it. From the description, "MATCH FULL" will do the
139 -- wrong thing, and "MATCH PARTIAL" isn't supported.
134 -- 140 --
135 constraint (scheme, value) references hierclass_values (scheme, value) 141 foreign key (scheme, value) references hierclass_values (scheme, value)
142 MATCH FULL
143 ON DELETE RESTRICT
144 ON UPDATE RESTRICT
136 ) 145 )
137 WITHOUT OIDS; 146 WITHOUT OIDS;
138 147
139 ------------------------------------------------------------ 148 ------------------------------------------------------------
140 -- Enumerated flat schemes. 149 -- Enumerated flat schemes.
164 pr bigint not null references PRs (id), 173 pr bigint not null references PRs (id),
165 scheme text not null references flatclass_names (name), 174 scheme text not null references flatclass_names (name),
166 value text , 175 value text ,
167 primary key (pr, scheme), 176 primary key (pr, scheme),
168 -- as above 177 -- as above
169 constraint (scheme, value) references flatclass_values (scheme, value) 178 foreign key (scheme, value) references flatclass_values (scheme, value)
179 MATCH FULL
180 ON DELETE RESTRICT
181 ON UPDATE RESTRICT
170 ) 182 )
171 WITHOUT OIDS; 183 WITHOUT OIDS;
172 184
173 ------------------------------------------------------------ 185 ------------------------------------------------------------
174 -- Text schemes. 186 -- Text schemes.
185 -- classification of PRs according to the text schemes 197 -- classification of PRs according to the text schemes
186 CREATE TABLE textclass_data ( 198 CREATE TABLE textclass_data (
187 pr bigint not null references PRs (id), 199 pr bigint not null references PRs (id),
188 scheme text not null references textclass_names (name), 200 scheme text not null references textclass_names (name),
189 value text , 201 value text ,
190 primary key (pr, scheme), 202 primary key (pr, scheme)
191 ) 203 )
192 WITHOUT OIDS; 204 WITHOUT OIDS;
193 205
194 ------------------------------------------------------------ 206 ------------------------------------------------------------
195 -- Tag schemes. 207 -- Tag schemes.
220 CREATE TABLE tagclass_data ( 232 CREATE TABLE tagclass_data (
221 pr bigint not null references PRs (id), 233 pr bigint not null references PRs (id),
222 scheme text not null references tagclass_names (name), 234 scheme text not null references tagclass_names (name),
223 value text , 235 value text ,
224 -- as above 236 -- as above
225 constraint (scheme, value) references tagclass_values (scheme, value) 237 foreign key (scheme, value) references tagclass_values (scheme, value)
238 MATCH FULL
239 ON DELETE RESTRICT
240 ON UPDATE RESTRICT
226 ) 241 )
227 WITHOUT OIDS; 242 WITHOUT OIDS;
228 243
229 -- view where tags are collected into a string 244 -- view where tags are collected into a string
230 -- XXX does concat(value) work, and if not, is there any way to do this? 245 -- string_agg() concatenates the value strings
231 CREATE VIEW tagclass_stringdata AS 246 CREATE VIEW tagclass_stringdata AS
232 SELECT pr, scheme, concat(value) as value 247 SELECT pr,
233 FROM tagclass_data 248 tagclass_data.scheme as scheme,
234 GROUP BY pr, scheme 249 string_agg(tagclass_data.value, ' '
250 ORDER BY tagclass_values.ordering) as value
251 FROM tagclass_data, tagclass_values
252 WHERE
253 tagclass_data.scheme = tagclass_values.scheme
254 AND tagclass_data.value = tagclass_values.value
255 GROUP BY pr, tagclass_data.scheme
235 ; 256 ;
236 257
237 ------------------------------------------------------------ 258 ------------------------------------------------------------
238 -- some views 259 -- some views
239 260
249 CREATE VIEW hierclass_data_ordered AS 270 CREATE VIEW hierclass_data_ordered AS
250 SELECT hierclass_data.pr as pr, 271 SELECT hierclass_data.pr as pr,
251 hierclass_data.scheme as scheme, 272 hierclass_data.scheme as scheme,
252 hierclass_names.ordering as schemeordering, 273 hierclass_names.ordering as schemeordering,
253 hierclass_data.value as value, 274 hierclass_data.value as value,
254 hierclass_values.ordering as valueordering, 275 hierclass_values.ordering as valueordering
255 FROM hierclass_data, hierclass_names, hierclass_values 276 FROM hierclass_data, hierclass_names, hierclass_values
256 WHERE 277 WHERE
257 hierclass_data.scheme = hierclass_names.name 278 hierclass_data.scheme = hierclass_names.name
258 AND hierclass_data.scheme = hierclass_values.scheme 279 AND hierclass_data.scheme = hierclass_values.scheme
259 AND hierclass_data.value = hierclass_values.value 280 AND hierclass_data.value = hierclass_values.value
262 CREATE VIEW flatclass_data_ordered AS 283 CREATE VIEW flatclass_data_ordered AS
263 SELECT flatclass_data.pr as pr, 284 SELECT flatclass_data.pr as pr,
264 flatclass_data.scheme as scheme, 285 flatclass_data.scheme as scheme,
265 flatclass_names.ordering as schemeordering, 286 flatclass_names.ordering as schemeordering,
266 flatclass_data.value as value, 287 flatclass_data.value as value,
267 flatclass_values.ordering as valueordering, 288 flatclass_values.ordering as valueordering
268 FROM flatclass_data, flatclass_names, flatclass_values 289 FROM flatclass_data, flatclass_names, flatclass_values
269 WHERE 290 WHERE
270 flatclass_data.scheme = flatclass_names.name 291 flatclass_data.scheme = flatclass_names.name
271 AND flatclass_data.scheme = flatclass_values.scheme 292 AND flatclass_data.scheme = flatclass_values.scheme
272 AND flatclass_data.value = flatclass_values.value 293 AND flatclass_data.value = flatclass_values.value
289 CREATE VIEW textclass_data_ordered AS 310 CREATE VIEW textclass_data_ordered AS
290 SELECT textclass_data.pr as pr, 311 SELECT textclass_data.pr as pr,
291 textclass_data.scheme as scheme, 312 textclass_data.scheme as scheme,
292 textclass_names.ordering as schemeordering, 313 textclass_names.ordering as schemeordering,
293 textclass_data.value as value, 314 textclass_data.value as value,
294 1 as valueordering, 315 1 as valueordering
295 FROM textclass_data, textclass_names 316 FROM textclass_data, textclass_names
296 WHERE 317 WHERE
297 textclass_data.scheme = textclass_names.name 318 textclass_data.scheme = textclass_names.name
298 ; 319 ;
299 320
300 CREATE VIEW tagclass_data_ordered AS 321 CREATE VIEW tagclass_data_ordered AS
301 SELECT tagclass_data.pr as pr, 322 SELECT tagclass_data.pr as pr,
302 tagclass_data.scheme as scheme, 323 tagclass_data.scheme as scheme,
303 tagclass_names.ordering as schemeordering, 324 tagclass_names.ordering as schemeordering,
304 tagclass_data.value as value, 325 tagclass_data.value as value,
305 tagclass_values.ordering as valueordering, 326 tagclass_values.ordering as valueordering
306 FROM tagclass_data, tagclass_names, tagclass_values 327 FROM tagclass_data, tagclass_names, tagclass_values
307 WHERE 328 WHERE
308 tagclass_data.scheme = tagclass_names.name 329 tagclass_data.scheme = tagclass_names.name
309 AND tagclass_data.scheme = tagclass_values.scheme 330 AND tagclass_data.scheme = tagclass_values.scheme
310 AND tagclass_data.value = tagclass_values.value 331 AND tagclass_data.value = tagclass_values.value
311 ; 332 ;
312 333
313 -- ordered version of tagclass_stringdata 334 -- ordered version of tagclass_stringdata
314 -- XXX does concat(value) work, and if not, is there any way to do this? 335 --
336 -- Note that schemeordering is uniquely defined by the group-by
337 -- and the min() on it is there to satisfy the cookiemonster.
338 --
315 CREATE VIEW tagclass_stringdata_ordered AS 339 CREATE VIEW tagclass_stringdata_ordered AS
316 SELECT pr, scheme, schemeordering, 340 SELECT pr, scheme, min(schemeordering),
317 concat(value) as value, first(valueordering) as valueordering 341 string_agg(value, ' ' ORDER BY valueordering) as value,
318 FROM tagclass_data 342 min(valueordering) as valueordering
319 ORDER BY valueordering 343 FROM tagclass_data_ordered
320 GROUP BY pr, scheme 344 GROUP BY pr, scheme
321 ; 345 ;
322 346
323 347
324 -- a view that combines all the classification data. 348 -- a view that combines all the classification data.