Revision 57521
Added by Antonis Lempesis over 4 years ago
stats_db_schema.sql | ||
---|---|---|
1 |
-- |
|
2 |
-- sqoopQL database dump |
|
3 |
-- |
|
4 |
|
|
5 | 1 |
SET statement_timeout = 0; |
6 | 2 |
SET client_encoding = 'UTF8'; |
7 | 3 |
SET standard_conforming_strings = on; |
8 | 4 |
SET check_function_bodies = false; |
9 | 5 |
SET client_min_messages = warning; |
10 | 6 |
|
11 |
-- |
|
12 |
-- Name: shadow; Type: SCHEMA; Schema: -; Owner: sqoop |
|
13 |
-- |
|
14 |
|
|
15 | 7 |
DROP SCHEMA IF EXISTS backup CASCADE; |
16 |
|
|
17 |
-- |
|
18 |
-- Name: shadow; Type: SCHEMA; Schema: -; Owner: sqoop |
|
19 |
-- |
|
20 | 8 |
DROP SCHEMA IF EXISTS shadow CASCADE; |
21 | 9 |
CREATE SCHEMA shadow; |
10 |
SET search_path = shadow, pg_catalog; |
|
22 | 11 |
|
23 |
--ALTER SCHEMA shadow OWNER TO sqoop; |
|
24 |
|
|
25 |
SET search_path = shadow, pg_catalog; |
|
26 |
|
|
27 |
|
|
28 |
-- |
|
29 |
-- Name: concept; Type: TABLE; Schema: public; Owner: dnet; Tablespace: |
|
30 |
-- |
|
31 |
|
|
32 | 12 |
CREATE TABLE shadow.concept ( |
33 | 13 |
id text NOT NULL, |
34 | 14 |
name text , |
35 | 15 |
category text |
36 | 16 |
); |
37 | 17 |
|
38 |
|
|
39 |
|
|
40 |
-- |
|
41 |
-- Name: datasource; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: |
|
42 |
-- |
|
43 |
|
|
44 | 18 |
CREATE TABLE shadow.datasource ( |
45 | 19 |
id text NOT NULL, |
46 | 20 |
name text , |
... | ... | |
51 | 25 |
dateofvalidation text, |
52 | 26 |
yearofvalidation integer, |
53 | 27 |
harvested TEXT DEFAULT 'false', |
54 |
piwik_id integer |
|
28 |
piwik_id integer, |
|
29 |
websiteurl text |
|
55 | 30 |
); |
56 | 31 |
|
57 |
-- |
|
58 |
-- Name: datasource_languages; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: |
|
59 |
-- |
|
60 |
|
|
61 | 32 |
CREATE TABLE shadow.datasource_languages ( |
62 | 33 |
id text NOT NULL, |
63 | 34 |
language text |
64 | 35 |
); |
65 | 36 |
|
66 |
-- |
|
67 |
-- Name: datasource_websites; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: |
|
68 |
-- |
|
69 |
|
|
70 | 37 |
CREATE TABLE shadow.datasource_websites ( |
71 | 38 |
id text NOT NULL, |
72 | 39 |
website text |
73 | 40 |
); |
74 | 41 |
|
75 |
-- |
|
76 |
-- Name: datasource_organizations; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: |
|
77 |
-- |
|
78 |
|
|
79 |
-- |
|
80 | 42 |
CREATE TABLE shadow.datasource_organizations ( |
81 | 43 |
id text NOT NULL, |
82 | 44 |
organization text NOT NULL |
83 | 45 |
); |
84 | 46 |
|
85 | 47 |
|
86 |
|
|
87 |
-- |
|
88 |
-- Name: result_datasources; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: |
|
89 |
-- |
|
90 |
|
|
91 | 48 |
CREATE TABLE shadow.result_datasources ( |
92 |
id text NOT NULL,
|
|
49 |
id integer NOT NULL,
|
|
93 | 50 |
datasource text NOT NULL |
94 | 51 |
); |
95 | 52 |
|
96 | 53 |
|
97 |
|
|
98 |
-- |
|
99 |
-- Name: datasource_results; Type: VIEW; Schema: shadow; Owner: sqoop |
|
100 |
-- |
|
101 |
|
|
102 |
--CREATE VIEW shadow.datasource_results AS |
|
103 |
-- SELECT result_datasources.datasource AS id, result_datasources.id AS result FROM result_datasources; |
|
104 |
|
|
105 |
-- |
|
106 |
-- Name: datasource_topics; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: |
|
107 |
-- Name: defaults; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: |
|
108 |
-- |
|
109 |
|
|
110 | 54 |
CREATE TABLE shadow.defaults ( |
111 | 55 |
tablename text NOT NULL, |
112 | 56 |
xaxis text, |
... | ... | |
117 | 61 |
tableorder integer NOT NULL |
118 | 62 |
); |
119 | 63 |
|
120 |
|
|
121 |
-- |
|
122 |
-- Name: category; Type: TABLE; Schema: public; Owner: dnet; Tablespace: |
|
123 |
-- |
|
124 | 64 |
CREATE TABLE shadow.category ( |
125 | 65 |
id text NOT NULL, |
126 | 66 |
name text, |
127 | 67 |
context text |
128 | 68 |
); |
129 | 69 |
|
130 |
-- |
|
131 |
-- Name: claim; Type: TABLE; Schema: public; Owner: dnet; Tablespace: |
|
132 |
-- |
|
133 |
|
|
134 | 70 |
CREATE TABLE shadow.claim ( |
135 | 71 |
id text NOT NULL, |
136 | 72 |
date text , |
137 | 73 |
userid text |
138 | 74 |
); |
139 | 75 |
|
140 |
|
|
141 |
-- |
|
142 |
-- Name: context; Type: TABLE; Schema: public; Owner: dnet; Tablespace: |
|
143 |
-- |
|
144 |
|
|
145 | 76 |
CREATE TABLE shadow.context ( |
146 | 77 |
id text NOT NULL, |
147 | 78 |
name text |
148 | 79 |
); |
149 | 80 |
|
150 |
-- |
|
151 |
-- Name: organization; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: |
|
152 |
-- |
|
153 |
|
|
154 | 81 |
CREATE TABLE shadow.organization ( |
155 | 82 |
id text NOT NULL, |
156 | 83 |
name text, |
157 | 84 |
country text |
158 | 85 |
); |
159 | 86 |
|
87 |
CREATE VIEW shadow.organization_datasources AS SELECT datasource_organizations.organization AS id, datasource_organizations.id AS datasource FROM datasource_organizations; |
|
160 | 88 |
|
161 |
|
|
162 |
-- |
|
163 |
-- Name: organization_datasources; Type: VIEW; Schema: shadow; Owner: sqoop |
|
164 |
-- |
|
165 |
|
|
166 |
CREATE VIEW shadow.organization_datasources AS |
|
167 |
SELECT datasource_organizations.organization AS id, datasource_organizations.id AS datasource FROM datasource_organizations; |
|
168 |
|
|
169 |
-- |
|
170 |
-- Name: project_organizations; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: |
|
171 |
-- |
|
172 |
|
|
173 | 89 |
CREATE TABLE shadow.project_organizations ( |
174 | 90 |
id text NOT NULL, |
175 | 91 |
organization text NOT NULL |
176 | 92 |
); |
177 | 93 |
|
178 |
|
|
179 |
-- |
|
180 |
-- Name: project_organizations; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: |
|
181 |
-- |
|
182 |
|
|
183 | 94 |
CREATE TABLE shadow.result_organizations ( |
184 |
id text NOT NULL,
|
|
95 |
id integer NOT NULL,
|
|
185 | 96 |
organization text NOT NULL |
186 | 97 |
); |
187 | 98 |
|
99 |
CREATE VIEW shadow.organization_projects AS SELECT project_organizations.id AS project, project_organizations.organization AS id FROM project_organizations; |
|
188 | 100 |
|
189 |
-- |
|
190 |
-- Name: organization_projects; Type: VIEW; Schema: shadow; Owner: sqoop |
|
191 |
-- |
|
192 |
|
|
193 |
CREATE VIEW shadow.organization_projects AS |
|
194 |
SELECT project_organizations.id AS project, project_organizations.organization AS id FROM project_organizations; |
|
195 |
|
|
196 |
-- |
|
197 |
-- Name: project; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: |
|
198 |
-- |
|
199 |
|
|
200 | 101 |
CREATE TABLE shadow.project ( |
201 | 102 |
id text NOT NULL, |
202 | 103 |
acronym text , |
... | ... | |
221 | 122 |
code text |
222 | 123 |
); |
223 | 124 |
|
224 |
-- |
|
225 |
-- Name: result_projects; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: |
|
226 |
-- |
|
227 |
|
|
228 | 125 |
CREATE TABLE shadow.project_oids ( |
229 | 126 |
id text NOT NULL, |
230 | 127 |
orid text |
231 | 128 |
); |
232 | 129 |
|
233 |
|
|
234 |
|
|
235 | 130 |
CREATE TABLE shadow.result_oids ( |
236 |
id text NOT NULL,
|
|
131 |
id integer NOT NULL,
|
|
237 | 132 |
orid text |
238 | 133 |
); |
239 | 134 |
|
240 |
|
|
241 | 135 |
CREATE TABLE shadow.organization_oids ( |
242 | 136 |
id text NOT NULL, |
243 | 137 |
orid text |
244 | 138 |
); |
245 | 139 |
|
246 |
|
|
247 | 140 |
CREATE TABLE shadow.datasource_oids ( |
248 | 141 |
id text NOT NULL, |
249 | 142 |
orid text |
250 | 143 |
); |
251 | 144 |
|
252 |
-- CREATE TABLE shadow.person_oids ( |
|
253 |
-- id text NOT NULL, |
|
254 |
-- orid text |
|
255 |
-- ); |
|
256 |
|
|
257 |
|
|
258 | 145 |
CREATE TABLE shadow.project_keywords ( |
259 | 146 |
id text NOT NULL, |
260 | 147 |
keyword text |
... | ... | |
266 | 153 |
subject text |
267 | 154 |
); |
268 | 155 |
|
269 |
|
|
270 |
--ALTER TABLE shadow.result_projects OWNER TO sqoop; |
|
271 |
|
|
272 | 156 |
CREATE TABLE shadow.project_results ( |
273 | 157 |
id text NOT NULL, |
274 | 158 |
result text NOT NULL, |
275 | 159 |
daysfromend integer |
276 | 160 |
); |
277 | 161 |
|
278 |
|
|
279 |
-- |
|
280 |
-- Name: result; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: |
|
281 |
-- |
|
282 |
|
|
283 | 162 |
CREATE TABLE shadow.result ( |
284 |
id text NOT NULL, |
|
163 |
id integer NOT NULL, |
|
164 |
original_id text, |
|
285 | 165 |
title text, |
286 | 166 |
publisher text, |
287 | 167 |
journal text, |
288 | 168 |
year integer, |
289 | 169 |
date text , |
290 |
-- access_mode text, |
|
291 | 170 |
bestlicense text, |
292 | 171 |
type text , |
293 | 172 |
embargo_end_date text, |
294 | 173 |
delayed text, |
295 | 174 |
authors integer, |
175 |
authornames text, |
|
296 | 176 |
source text, |
297 | 177 |
abstract text |
298 | 178 |
); |
299 | 179 |
|
300 |
-- |
|
301 |
-- Name: result_extra; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: |
|
302 |
-- |
|
303 |
|
|
304 | 180 |
CREATE TABLE shadow.result_extra ( |
305 |
id text NOT NULL,
|
|
181 |
id integer NOT NULL,
|
|
306 | 182 |
title text, |
307 | 183 |
source text |
308 | 184 |
); |
309 | 185 |
|
310 |
-- |
|
311 |
-- Name: result_claims; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: |
|
312 |
-- |
|
313 |
|
|
314 | 186 |
CREATE TABLE shadow.result_claims ( |
315 |
id text NOT NULL,
|
|
187 |
id integer NOT NULL,
|
|
316 | 188 |
claim text NOT NULL |
317 | 189 |
); |
318 | 190 |
|
319 | 191 |
CREATE TABLE shadow.result_citations ( |
320 |
id text NOT NULL,
|
|
192 |
id integer NOT NULL,
|
|
321 | 193 |
result text NOT NULL |
322 |
-- trust text, |
|
323 |
-- provenance text, |
|
324 |
-- citation text |
|
325 | 194 |
); |
326 | 195 |
|
327 |
|
|
328 |
-- |
|
329 |
-- Name: result_classifications; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: |
|
330 |
-- |
|
331 |
|
|
332 | 196 |
CREATE TABLE shadow.result_classifications ( |
333 |
id text NOT NULL,
|
|
197 |
id integer NOT NULL,
|
|
334 | 198 |
type text NOT NULL |
335 | 199 |
); |
336 | 200 |
|
337 |
-- |
|
338 |
-- Name: result_concepts; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: |
|
339 |
-- |
|
340 |
|
|
341 | 201 |
CREATE TABLE shadow.result_concepts ( |
342 |
id text NOT NULL,
|
|
202 |
id integer NOT NULL,
|
|
343 | 203 |
concept text NOT NULL |
344 | 204 |
); |
345 | 205 |
|
346 |
-- |
|
347 |
-- Name: result_languages; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: |
|
348 |
-- |
|
349 |
|
|
350 | 206 |
CREATE TABLE shadow.result_languages ( |
351 |
id text NOT NULL,
|
|
352 |
language text NOT NULL
|
|
207 |
id integer NOT NULL,
|
|
208 |
language text |
|
353 | 209 |
); |
354 | 210 |
|
355 |
|
|
356 |
-- |
|
357 |
-- Name: result_results; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: |
|
358 |
-- |
|
359 |
|
|
360 | 211 |
CREATE TABLE shadow.result_results ( |
361 |
id text NOT NULL, |
|
362 |
result text NOT NULL |
|
212 |
original_id text NOT NULL,
|
|
213 |
result_original_id text NOT NULL
|
|
363 | 214 |
); |
364 | 215 |
|
365 |
|
|
366 |
|
|
367 |
-- |
|
368 |
-- Name: result_topics; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace: |
|
369 |
-- |
|
370 |
|
|
371 | 216 |
CREATE TABLE shadow.result_topics ( |
372 |
id text NOT NULL,
|
|
217 |
id integer NOT NULL,
|
|
373 | 218 |
topic text |
374 | 219 |
); |
375 | 220 |
|
376 |
|
|
377 | 221 |
CREATE TABLE shadow.result_descriptions ( |
378 |
id text NOT NULL,
|
|
222 |
id integer NOT NULL,
|
|
379 | 223 |
description text |
380 | 224 |
); |
381 | 225 |
|
382 | 226 |
CREATE TABLE shadow.result_pids ( |
383 |
id text NOT NULL,
|
|
227 |
id integer NOT NULL,
|
|
384 | 228 |
type text , |
385 | 229 |
pid text |
386 | 230 |
); |
... | ... | |
393 | 237 |
|
394 | 238 |
); |
395 | 239 |
|
396 |
----------- |
|
397 |
--functions |
|
398 |
----------- |
|
240 |
CREATE OR REPLACE FUNCTION shadow.fix_result_ids() RETURNS void LANGUAGE plpgsql VOLATILE COST 100 AS $BODY$ |
|
241 |
BEGIN |
|
242 |
|
|
243 |
create index foo ON result(original_id); |
|
244 |
|
|
245 |
alter table shadow.project_results add column result_id int; |
|
246 |
update shadow.project_results pr set result_id = r.id from (select id, original_id from result) r where r.original_id=pr.result; |
|
247 |
alter table shadow.project_results drop column result; |
|
248 |
alter table shadow.project_results rename COLUMN result_id TO result; |
|
249 |
|
|
250 |
alter table shadow.result_results add column id int; |
|
251 |
alter table shadow.result_results add column result int; |
|
252 |
update shadow.result_results rr set id = r.id from result r where r.original_id=rr.original_id; |
|
253 |
update shadow.result_results rr set result = r.id from result r where r.original_id=rr.result_original_id; |
|
254 |
alter table shadow.result_results drop column original_id; |
|
255 |
alter table shadow.result_results drop column result_original_id; |
|
256 |
|
|
257 |
drop index foo; |
|
258 |
|
|
259 |
END $BODY$; |
|
260 |
|
|
261 |
ALTER FUNCTION shadow.fix_result_ids() OWNER TO sqoop; |
|
262 |
|
|
399 | 263 |
CREATE OR REPLACE FUNCTION shadow.extra_defaults_datasource() RETURNS void LANGUAGE plpgsql VOLATILE COST 100 AS $BODY$ |
400 | 264 |
BEGIN |
401 | 265 |
|
... | ... | |
415 | 279 |
|
416 | 280 |
ALTER FUNCTION shadow.extra_defaults_datasource() OWNER TO sqoop; |
417 | 281 |
|
418 |
|
|
419 | 282 |
-- |
420 | 283 |
-- Project Results Extra Inserts |
421 | 284 |
-- |
... | ... | |
430 | 293 |
|
431 | 294 |
ALTER FUNCTION shadow.update_project_results() OWNER TO sqoop; |
432 | 295 |
|
433 |
|
|
434 |
|
|
435 | 296 |
-- |
436 | 297 |
-- Project Has Publications Extra Inserts |
437 | 298 |
-- |
... | ... | |
442 | 303 |
|
443 | 304 |
ALTER FUNCTION shadow.project_has_pubs() OWNER TO sqoop; |
444 | 305 |
|
445 |
|
|
446 | 306 |
-- |
447 | 307 |
-- Project Publications Count Updates |
448 | 308 |
-- |
... | ... | |
453 | 313 |
|
454 | 314 |
ALTER FUNCTION shadow.project_pubs_count() OWNER TO sqoop; |
455 | 315 |
|
456 |
|
|
457 |
|
|
458 | 316 |
-- |
459 | 317 |
-- Project Delayed Publications |
460 | 318 |
-- |
... | ... | |
465 | 323 |
|
466 | 324 |
ALTER FUNCTION shadow.project_delayedpubs() OWNER TO sqoop; |
467 | 325 |
|
468 |
|
|
469 | 326 |
-- |
470 | 327 |
-- Project daysforlastpub |
471 | 328 |
-- |
... | ... | |
511 | 368 |
UPDATE shadow.result r SET projects = prr.ids FROM (SELECT pr.result AS rid, array_agg(distinct pr.id) AS ids FROM shadow.project_results pr GROUP BY pr.result) AS prr WHERE r.id = prr.rid; |
512 | 369 |
|
513 | 370 |
-- todo fix this query |
514 |
-- UPDATE shadow.result r SET datasources = drr.ids FROM (SELECT dr.result AS rid, array_agg(distinct dr.id) AS ids FROM shadow.project_results pr GROUP BY pr.result) AS prr WHERE r.id = prr.rid;
|
|
371 |
UPDATE shadow.result r SET datasources = drr.ids FROM (SELECT dr.result AS rid, array_agg(distinct dr.id) AS ids FROM shadow.datasource_results dr GROUP BY dr.result) AS drr WHERE r.id = drr.rid;
|
|
515 | 372 |
|
516 | 373 |
END $BODY$; |
517 | 374 |
|
... | ... | |
564 | 421 |
CREATE INDEX project_results_result ON "shadow"."project_results" USING btree (result); |
565 | 422 |
CREATE INDEX project_results_project ON "shadow"."project_results" USING btree (id); |
566 | 423 |
|
567 |
CREATE INDEX result_oids_id ON "shadow".result_oids USING btree (id COLLATE pg_catalog."default");
|
|
424 |
CREATE INDEX result_oids_id ON "shadow".result_oids USING btree (id); |
|
568 | 425 |
CREATE INDEX result_oids_oid ON "shadow".result_oids USING btree(orid COLLATE pg_catalog."default"); |
569 | 426 |
|
570 |
CREATE INDEX result_pids_id ON "shadow".result_pids USING btree (id COLLATE pg_catalog."default");
|
|
427 |
CREATE INDEX result_pids_id ON "shadow".result_pids USING btree (id); |
|
571 | 428 |
CREATE INDEX result_pids_type ON "shadow".result_pids USING btree (type COLLATE pg_catalog."default"); |
572 | 429 |
CREATE INDEX result_pids_pid ON "shadow".result_pids USING btree(pid COLLATE pg_catalog."default"); |
573 | 430 |
|
574 |
CREATE INDEX result_extra_id ON "shadow".result_extra USING btree(id COLLATE pg_catalog."default");
|
|
431 |
CREATE INDEX result_extra_id ON "shadow".result_extra USING btree(id); |
|
575 | 432 |
|
576 | 433 |
CREATE INDEX res_class_type ON shadow.result_classifications USING btree (type COLLATE pg_catalog."default"); |
577 |
CREATE INDEX res_class_id ON shadow.result_classifications USING btree (id COLLATE pg_catalog."default");
|
|
434 |
CREATE INDEX res_class_id ON shadow.result_classifications USING btree (id); |
|
578 | 435 |
|
579 | 436 |
CREATE INDEX res_dtsrc_dtsrc ON shadow.result_datasources USING btree (datasource COLLATE pg_catalog."default"); |
580 |
CREATE INDEX res_dtsrc_id ON shadow.result_datasources USING btree (id COLLATE pg_catalog."default");
|
|
437 |
CREATE INDEX res_dtsrc_id ON shadow.result_datasources USING btree (id); |
|
581 | 438 |
|
582 | 439 |
CREATE INDEX res_lang_lang ON shadow.result_languages USING btree (language COLLATE pg_catalog."default"); |
583 | 440 |
|
... | ... | |
588 | 445 |
CREATE INDEX proj_org_org ON shadow.project_organizations USING btree (organization COLLATE pg_catalog."default"); |
589 | 446 |
CREATE INDEX proj_org_id ON shadow.project_organizations USING btree (id COLLATE pg_catalog."default"); |
590 | 447 |
|
591 |
CREATE INDEX res_res_id ON shadow.result_results USING btree (id COLLATE pg_catalog."default");
|
|
592 |
CREATE INDEX res_res_res ON shadow.result_results USING btree (result COLLATE pg_catalog."default");
|
|
448 |
CREATE INDEX res_res_id ON shadow.result_results USING btree (id); |
|
449 |
CREATE INDEX res_res_res ON shadow.result_results USING btree (result); |
|
593 | 450 |
|
594 |
CREATE INDEX res_lang_id ON shadow.result_languages USING btree (id COLLATE pg_catalog."default");
|
|
451 |
CREATE INDEX res_lang_id ON shadow.result_languages USING btree (id); |
|
595 | 452 |
|
596 |
CREATE INDEX res_conc_id ON shadow.result_concepts USING btree (id COLLATE pg_catalog."default");
|
|
453 |
CREATE INDEX res_conc_id ON shadow.result_concepts USING btree (id); |
|
597 | 454 |
CREATE INDEX res_conc_conc ON shadow.result_concepts USING btree (concept COLLATE pg_catalog."default"); |
598 | 455 |
END;$$; |
599 | 456 |
|
... | ... | |
628 | 485 |
CREATE or replace FUNCTION "shadow".create_charts() RETURNS void LANGUAGE plpgsql AS $$ |
629 | 486 |
BEGIN |
630 | 487 |
-- country nums |
631 |
-- CREATE TABLE "shadow".numbers_country AS SELECT org.country AS country, count(distinct rd.datasource) AS datasources, count(distinct r.id) AS publications FROM "shadow".result r, "shadow".result_datasources rd, "shadow".datasource d, "shadow".datasource_organizations dor, "shadow".organization org WHERE r.id=rd.id AND rd.datasource=d.id AND d.id=dor.id AND dor.organization=org.id AND r.type='publication' AND r.bestlicense='Open Access' GROUP BY org.country;
|
|
632 |
-- --
|
|
633 |
-- -- -- country charts
|
|
634 |
-- CREATE TABLE "shadow".chart_country_year AS SELECT org.country AS country, r.year AS year, count(distinct r.id) AS publications FROM "shadow".result r, "shadow".result_datasources rd, "shadow".datasource d, "shadow".datasource_organizations dor, "shadow".organization org WHERE r.id=rd.id AND rd.datasource=d.id AND rd.datasource=dor.id AND dor.organization=org.id AND r.type='publication' AND r.bestlicense='Open Access' and r.year>='1990' AND r.year<=extract(YEAR from now()) group by org.country, r.year ORDER BY org.country, r.year;
|
|
635 |
-- CREATE TABLE "shadow".chart_country_datasources AS SELECT org.country AS country, d.name AS datasource, count(distinct r.id) AS publications FROM "shadow".result r, "shadow".result_datasources rd, "shadow".datasource d, "shadow".datasource_organizations dor, "shadow".organization org WHERE r.id=rd.id AND rd.datasource=d.id AND d.id=dor.id AND dor.organization=org.id AND r.type='publication' AND r.bestlicense='Open Access' GROUP BY org.country, d.name ORDER BY org.country, count(distinct r.id) DESC;
|
|
636 |
-- CREATE TABLE "shadow".chart_country_type AS SELECT org.country AS country, rc.type AS type, count(distinct r.id) AS publications FROM "shadow".result r, "shadow".result_datasources rd, "shadow".datasource d, "shadow".result_classifications rc, "shadow".datasource_organizations dor, "shadow".organization org WHERE r.id=rd.id AND r.id=rc.id AND rd.datasource=d.id AND rd.datasource=dor.id AND dor.organization=org.id AND r.type='publication' AND r.bestlicense='Open Access' GROUP BY org.country, rc.type;
|
|
637 |
-- CREATE TABLE "shadow".chart_country_fp7 AS SELECT org.country AS country, r.year AS year, count(distinct r.id) AS publications FROM "shadow".result r, "shadow".result_datasources rd, "shadow".datasource d, "shadow".datasource_organizations dor, "shadow".organization org, "shadow".project_results pr, "shadow".project p WHERE r.id=rd.id AND rd.datasource=d.id AND rd.datasource=dor.id AND dor.organization=org.id AND r.id=pr.result AND pr.id=p.id AND p.funding_lvl0='FP7' AND r.type='publication' AND r.year>='1990' AND r.year<=extract(YEAR from now()) GROUP BY org.country, r.year ORDER BY org.country, r.year;
|
|
638 |
-- --
|
|
639 |
-- -- -- datasource charts
|
|
640 |
-- CREATE TABLE "shadow".chart_datasource_type AS SELECT rd.datasource, rc.type, count(distinct rd.id) FROM "shadow".result_datasources rd, "shadow".result_classifications rc WHERE rd.id=rc.id GROUP BY rd.datasource, rc.type;
|
|
641 |
-- CREATE TABLE "shadow".chart_datasource_year AS SELECT rd.datasource, r.year, count(distinct rd.id) FROM "shadow".result r, "shadow".result_datasources rd WHERE rd.id=r.id GROUP By rd.datasource, r.year;
|
|
642 |
-- CREATE TABLE "shadow".chart_datasource_funders AS SELECT rd.datasource, p.funder, count(distinct rd.id) FROM "shadow".result_datasources rd, "shadow".project p, "shadow".project_results pr WHERE p.id=pr.id AND pr.result=rd.id GROUP BY rd.datasource, p.funder;
|
|
643 |
-- CREATE TABLE "shadow".chart_datasource_projects_pubs AS SELECT rd.datasource, p.title, count(distinct rd.id) FROM "shadow".result_datasources rd, "shadow".project p, "shadow".project_results pr, "shadow".result r WHERE p.id=pr.id AND pr.result=rd.id AND pr.result=r.id AND r.type='publication' GROUP BY rd.datasource, p.title;
|
|
644 |
-- CREATE TABLE "shadow".chart_datasource_projects_data AS SELECT rd.datasource, p.title, count(distinct rd.id) FROM "shadow".result_datasources rd, "shadow".project p, "shadow".project_results pr, "shadow".result r WHERE p.id=pr.id AND pr.result=rd.id AND pr.result=r.id and r.type='dataset' GROUP BY rd.datasource, p.title;
|
|
645 |
-- --
|
|
646 |
-- -- project charts
|
|
647 |
-- CREATE TABLE "shadow".chart_project_year AS SELECT p.id, r.year, count( distinct r.id) FROM "shadow".result r, "shadow".project_results pr, "shadow".project p WHERE r.id=pr.result AND p.id=pr.id AND r.year>=p.start_year GROUP BY p.id, r.year;
|
|
648 |
-- CREATE TABLE "shadow".chart_project_license AS SELECT pr.id, r.bestlicense, count(distinct r.id) FROM "shadow".result r, "shadow".project_results pr WHERE r.id=pr.result AND r.type='publication' GROUP BY pr.id, r.bestlicense;
|
|
649 |
-- CREATE TABLE "shadow".chart_project_repos AS SELECT pr.id, d.name, count (distinct r.id) FROM "shadow".result r, "shadow".project_results pr, "shadow".datasource d, "shadow".datasource_results dr WHERE r.id=dr.result AND d.id=dr.id AND r.id=pr.result AND r.type='publication' GROUP BY pr.id, d.name;
|
|
488 |
CREATE TABLE "shadow".numbers_country AS SELECT org.country AS country, count(distinct rd.datasource) AS datasources, count(distinct r.id) AS publications FROM "shadow".result r, "shadow".result_datasources rd, "shadow".datasource d, "shadow".datasource_organizations dor, "shadow".organization org WHERE r.id=rd.id AND rd.datasource=d.id AND d.id=dor.id AND dor.organization=org.id AND r.type='publication' AND r.bestlicense='Open Access' GROUP BY org.country; |
|
489 |
-- |
|
490 |
-- -- country charts |
|
491 |
CREATE TABLE "shadow".chart_country_year AS SELECT org.country AS country, r.year AS year, count(distinct r.id) AS publications FROM "shadow".result r, "shadow".result_datasources rd, "shadow".datasource d, "shadow".datasource_organizations dor, "shadow".organization org WHERE r.id=rd.id AND rd.datasource=d.id AND rd.datasource=dor.id AND dor.organization=org.id AND r.type='publication' AND r.bestlicense='Open Access' and r.year>='1990' AND r.year<=extract(YEAR from now()) group by org.country, r.year ORDER BY org.country, r.year; |
|
492 |
CREATE TABLE "shadow".chart_country_datasources AS SELECT org.country AS country, d.name AS datasource, count(distinct r.id) AS publications FROM "shadow".result r, "shadow".result_datasources rd, "shadow".datasource d, "shadow".datasource_organizations dor, "shadow".organization org WHERE r.id=rd.id AND rd.datasource=d.id AND d.id=dor.id AND dor.organization=org.id AND r.type='publication' AND r.bestlicense='Open Access' GROUP BY org.country, d.name ORDER BY org.country, count(distinct r.id) DESC; |
|
493 |
CREATE TABLE "shadow".chart_country_type AS SELECT org.country AS country, rc.type AS type, count(distinct r.id) AS publications FROM "shadow".result r, "shadow".result_datasources rd, "shadow".datasource d, "shadow".result_classifications rc, "shadow".datasource_organizations dor, "shadow".organization org WHERE r.id=rd.id AND r.id=rc.id AND rd.datasource=d.id AND rd.datasource=dor.id AND dor.organization=org.id AND r.type='publication' AND r.bestlicense='Open Access' GROUP BY org.country, rc.type; |
|
494 |
CREATE TABLE "shadow".chart_country_fp7 AS SELECT org.country AS country, r.year AS year, count(distinct r.id) AS publications FROM "shadow".result r, "shadow".result_datasources rd, "shadow".datasource d, "shadow".datasource_organizations dor, "shadow".organization org, "shadow".project_results pr, "shadow".project p WHERE r.id=rd.id AND rd.datasource=d.id AND rd.datasource=dor.id AND dor.organization=org.id AND r.id=pr.result AND pr.id=p.id AND p.funding_lvl0='FP7' AND r.type='publication' AND r.year>='1990' AND r.year<=extract(YEAR from now()) GROUP BY org.country, r.year ORDER BY org.country, r.year; |
|
495 |
-- |
|
496 |
-- -- datasource charts |
|
497 |
CREATE TABLE "shadow".chart_datasource_type AS SELECT rd.datasource, rc.type, count(distinct rd.id) FROM "shadow".result_datasources rd, "shadow".result_classifications rc WHERE rd.id=rc.id GROUP BY rd.datasource, rc.type; |
|
498 |
CREATE TABLE "shadow".chart_datasource_year AS SELECT rd.datasource, r.year, count(distinct rd.id) FROM "shadow".result r, "shadow".result_datasources rd WHERE rd.id=r.id GROUP By rd.datasource, r.year; |
|
499 |
CREATE TABLE "shadow".chart_datasource_funders AS SELECT rd.datasource, p.funder, count(distinct rd.id) FROM "shadow".result_datasources rd, "shadow".project p, "shadow".project_results pr WHERE p.id=pr.id AND pr.result=rd.id GROUP BY rd.datasource, p.funder; |
|
500 |
CREATE TABLE "shadow".chart_datasource_projects_pubs AS SELECT rd.datasource, p.title, count(distinct rd.id) FROM "shadow".result_datasources rd, "shadow".project p, "shadow".project_results pr, "shadow".result r WHERE p.id=pr.id AND pr.result=rd.id AND pr.result=r.id AND r.type='publication' GROUP BY rd.datasource, p.title; |
|
501 |
CREATE TABLE "shadow".chart_datasource_projects_data AS SELECT rd.datasource, p.title, count(distinct rd.id) FROM "shadow".result_datasources rd, "shadow".project p, "shadow".project_results pr, "shadow".result r WHERE p.id=pr.id AND pr.result=rd.id AND pr.result=r.id and r.type='dataset' GROUP BY rd.datasource, p.title; |
|
502 |
-- |
|
503 |
-- project charts |
|
504 |
CREATE TABLE "shadow".chart_project_year AS SELECT p.id, r.year, count( distinct r.id) FROM "shadow".result r, "shadow".project_results pr, "shadow".project p WHERE r.id=pr.result AND p.id=pr.id AND r.year>=p.start_year GROUP BY p.id, r.year; |
|
505 |
CREATE TABLE "shadow".chart_project_license AS SELECT pr.id, r.bestlicense, count(distinct r.id) FROM "shadow".result r, "shadow".project_results pr WHERE r.id=pr.result AND r.type='publication' GROUP BY pr.id, r.bestlicense; |
|
506 |
CREATE TABLE "shadow".chart_project_repos AS SELECT pr.id, d.name, count (distinct r.id) FROM "shadow".result r, "shadow".project_results pr, "shadow".datasource d, "shadow".datasource_results dr WHERE r.id=dr.result AND d.id=dr.id AND r.id=pr.result AND r.type='publication' GROUP BY pr.id, d.name; |
|
650 | 507 |
END;$$; |
651 | 508 |
|
652 |
-- |
|
653 |
-- Name: create_charts(); Type: FUNCTION; Schema: shadow; Owner: sqoop |
|
654 |
-- |
|
655 | 509 |
CREATE or replace FUNCTION "shadow".create_chart_indexes() RETURNS void LANGUAGE plpgsql AS $$ |
656 | 510 |
BEGIN |
657 | 511 |
-- country nums |
658 |
-- CREATE INDEX numbers_country_country ON "shadow".numbers_country USING btree(country);
|
|
512 |
CREATE INDEX numbers_country_country ON "shadow".numbers_country USING btree(country); |
|
659 | 513 |
|
660 |
-- country charts |
|
661 |
-- CREATE INDEX chart_country_year_country ON "shadow".chart_country_year USING btree(country); |
|
662 |
-- CREATE INDEX chart_country_datasources_country ON "shadow".chart_country_datasources USING btree(country); |
|
663 |
-- CREATE INDEX chart_country_type_country ON "shadow".chart_country_type USING btree(country); |
|
664 |
-- CREATE INDEX chart_country_fp7_country ON "shadow".chart_country_fp7 USING btree(country); |
|
514 |
CREATE INDEX chart_country_year_country ON "shadow".chart_country_year USING btree(country); |
|
515 |
CREATE INDEX chart_country_datasources_country ON "shadow".chart_country_datasources USING btree(country); |
|
516 |
CREATE INDEX chart_country_type_country ON "shadow".chart_country_type USING btree(country); |
|
517 |
CREATE INDEX chart_country_fp7_country ON "shadow".chart_country_fp7 USING btree(country); |
|
665 | 518 |
|
666 |
-- datasource |
|
667 |
-- CREATE INDEX chart_datasource_type_datasource ON "shadow".chart_datasource_type USING btree(datasource); |
|
668 |
-- CREATE INDEX chart_datasource_year_datasource ON "shadow".chart_datasource_year USING btree(datasource); |
|
669 |
-- CREATE INDEX chart_datasource_funders_datasource ON "shadow".chart_datasource_funders USING btree(datasource); |
|
670 |
-- CREATE INDEX chart_datasource_projects_pubs_datasource ON "shadow".chart_datasource_projects_pubs USING btree(datasource); |
|
671 |
-- CREATE INDEX chart_datasource_projects_data_datasource ON "shadow".chart_datasource_projects_data USING btree(datasource); |
|
519 |
CREATE INDEX chart_datasource_type_datasource ON "shadow".chart_datasource_type USING btree(datasource); |
|
520 |
CREATE INDEX chart_datasource_year_datasource ON "shadow".chart_datasource_year USING btree(datasource); |
|
521 |
CREATE INDEX chart_datasource_funders_datasource ON "shadow".chart_datasource_funders USING btree(datasource); |
|
522 |
CREATE INDEX chart_datasource_projects_pubs_datasource ON "shadow".chart_datasource_projects_pubs USING btree(datasource); |
|
523 |
CREATE INDEX chart_datasource_projects_data_datasource ON "shadow".chart_datasource_projects_data USING btree(datasource); |
|
672 | 524 |
|
673 |
-- project |
|
674 |
-- CREATE INDEX chart_project_year_id ON "shadow".chart_project_year USING btree(id); |
|
675 |
-- CREATE INDEX chart_project_license_id ON "shadow".chart_project_license USING btree(id); |
|
676 |
-- CREATE INDEX chart_project_repos_id ON "shadow".chart_project_repos USING btree(id); |
|
525 |
CREATE INDEX chart_project_year_id ON "shadow".chart_project_year USING btree(id); |
|
526 |
CREATE INDEX chart_project_license_id ON "shadow".chart_project_license USING btree(id); |
|
527 |
CREATE INDEX chart_project_repos_id ON "shadow".chart_project_repos USING btree(id); |
|
677 | 528 |
END;$$; |
678 | 529 |
|
679 |
-- |
|
680 |
-- Name: clean_tables(); Type: FUNCTION; Schema: shadow; Owner: sqoop |
|
681 |
-- |
|
682 | 530 |
CREATE or replace FUNCTION "shadow".clean_tables() RETURNS void LANGUAGE plpgsql AS $$ |
683 | 531 |
BEGIN |
684 | 532 |
CREATE TABLE "shadow".rd_distinct AS SELECT DISTINCT * FROM "shadow".result_datasources; |
... | ... | |
691 | 539 |
-- DROP TABLE "shadow".rd_distinct; |
692 | 540 |
END;$$; |
693 | 541 |
|
694 |
|
|
695 | 542 |
CREATE OR REPLACE FUNCTION "shadow".insert_countries() RETURNS void LANGUAGE plpgsql AS $$ |
696 | 543 |
BEGIN |
697 | 544 |
INSERT INTO shadow.country (code, name, continent_code, continent_name) VALUES ('AD', 'Andorra', 'EU', 'Europe'); |
... | ... | |
948 | 795 |
ALTER TABLE "shadow".project RENAME TO tproject; |
949 | 796 |
ALTER TABLE "shadow".organization RENAME TO torganization; |
950 | 797 |
|
951 |
CREATE VIEW "shadow".result AS SELECT tresult.id, tresult.id AS result_projects, tresult.id AS result_datasources, tresult.publisher, tresult.year, tresult.bestlicense, tresult.bestlicense AS access_mode, tresult.type, tresult.embargo_end_date, tresult.delayed, tresult.authors, tresult.funders, tresult.funding_lvl0 AS arfunding_lvl0, tresult.projects, tresult.datasources, 1 AS number, tresult.title as title, tresult.source as source, tresult.abstract as abstract FROM tresult;
|
|
952 |
CREATE VIEW "shadow".datasource AS SELECT tdatasource.id, tdatasource.name, tdatasource.type, tdatasource.compatibility, tdatasource.dateofvalidation, tdatasource.yearofvalidation, tdatasource.harvested, tdatasource.piwik_id, tdatasource.latitude, tdatasource.longitude, tdatasource.id AS datasource_results, tdatasource.id AS datasource_organizations, 1 AS number FROM tdatasource; |
|
798 |
CREATE VIEW "shadow".result AS SELECT tresult.id, tresult.original_id as original_id, tresult.id AS result_projects, tresult.id AS result_datasources, tresult.publisher, tresult.year, tresult.bestlicense, tresult.bestlicense AS access_mode, tresult.type, tresult.embargo_end_date, tresult.delayed, tresult.authors, tresult.authornames, tresult.funders, tresult.funding_lvl0 AS arfunding_lvl0, tresult.projects, tresult.datasources, 1 AS number, tresult.title as title, tresult.source as source, tresult.abstract as abstract FROM tresult;
|
|
799 |
CREATE VIEW "shadow".datasource AS SELECT tdatasource.id, tdatasource.name, tdatasource.type, tdatasource.compatibility, tdatasource.dateofvalidation, tdatasource.yearofvalidation, tdatasource.harvested, tdatasource.piwik_id, tdatasource.latitude, tdatasource.longitude, tdatasource.websiteurl, tdatasource.id AS datasource_results, tdatasource.id AS datasource_organizations, 1 AS number FROM tdatasource;
|
|
953 | 800 |
CREATE VIEW "shadow".project AS SELECT tproject.id, tproject.acronym, tproject.title, tproject.funder, tproject.funding_lvl0, tproject.funding_lvl1, tproject.funding_lvl2, tproject.funding_lvl3, tproject.sc39, tproject.type, tproject.start_year, tproject.end_year, tproject.duration, tproject.haspubs, tproject.numpubs, tproject.enddate, tproject.startdate, tproject.daysforlastpub, tproject.delayedpubs, tproject.callidentifier, tproject.code, tproject.id AS project_results, tproject.id AS project_organizations, 1 AS number FROM tproject; |
954 | 801 |
CREATE VIEW "shadow".organization AS SELECT torganization.id, torganization.name, torganization.country, torganization.id AS organization_datasources, torganization.id AS organization_projects, 1 AS number FROM torganization; |
955 | 802 |
|
Also available in: Unified diff
using int ids in results