1
|
--
|
2
|
-- sqoopQL database dump
|
3
|
--
|
4
|
|
5
|
SET statement_timeout = 0;
|
6
|
SET client_encoding = 'UTF8';
|
7
|
SET standard_conforming_strings = on;
|
8
|
SET check_function_bodies = false;
|
9
|
SET client_min_messages = warning;
|
10
|
|
11
|
--
|
12
|
-- Name: shadow; Type: SCHEMA; Schema: -; Owner: sqoop
|
13
|
--
|
14
|
|
15
|
DROP SCHEMA IF EXISTS backup CASCADE;
|
16
|
|
17
|
--
|
18
|
-- Name: shadow; Type: SCHEMA; Schema: -; Owner: sqoop
|
19
|
--
|
20
|
DROP SCHEMA IF EXISTS shadow CASCADE;
|
21
|
CREATE SCHEMA shadow;
|
22
|
|
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
|
CREATE TABLE shadow.concept (
|
33
|
id text NOT NULL,
|
34
|
name text ,
|
35
|
category text
|
36
|
);
|
37
|
|
38
|
|
39
|
|
40
|
--
|
41
|
-- Name: datasource; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace:
|
42
|
--
|
43
|
|
44
|
CREATE TABLE shadow.datasource (
|
45
|
id text NOT NULL,
|
46
|
datasource_results text NOT NULL,
|
47
|
datasource_organizations text NOT NULL,
|
48
|
datasource_languages text NOT NULL,
|
49
|
datasource_topics text NOT NULL,
|
50
|
name text ,
|
51
|
type text,
|
52
|
compatibility text,
|
53
|
latitude text,
|
54
|
longitude text,
|
55
|
dateofvalidation text,
|
56
|
yearofvalidation integer,
|
57
|
websiteurl text,
|
58
|
piwik_id integer,
|
59
|
harvested TEXT DEFAULT 'false',
|
60
|
deletedbyinference TEXT,
|
61
|
number integer DEFAULT 1 NOT NULL
|
62
|
);
|
63
|
|
64
|
--
|
65
|
-- Name: datasource_languages; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace:
|
66
|
--
|
67
|
|
68
|
CREATE TABLE shadow.datasource_languages (
|
69
|
id text NOT NULL,
|
70
|
language text
|
71
|
);
|
72
|
|
73
|
|
74
|
--
|
75
|
-- Name: datasource_organizations; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace:
|
76
|
--
|
77
|
|
78
|
--
|
79
|
CREATE TABLE shadow.datasource_organizations (
|
80
|
id text NOT NULL,
|
81
|
organization text NOT NULL
|
82
|
);
|
83
|
|
84
|
|
85
|
|
86
|
--
|
87
|
-- Name: result_datasources; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace:
|
88
|
--
|
89
|
|
90
|
CREATE TABLE shadow.result_datasources (
|
91
|
id text NOT NULL,
|
92
|
datasource text NOT NULL
|
93
|
);
|
94
|
|
95
|
|
96
|
|
97
|
--
|
98
|
-- Name: datasource_results; Type: VIEW; Schema: shadow; Owner: sqoop
|
99
|
--
|
100
|
|
101
|
--CREATE VIEW shadow.datasource_results AS
|
102
|
-- SELECT result_datasources.datasource AS id, result_datasources.id AS result FROM result_datasources;
|
103
|
|
104
|
--
|
105
|
-- Name: datasource_topics; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace:
|
106
|
-- Name: defaults; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace:
|
107
|
--
|
108
|
|
109
|
CREATE TABLE shadow.defaults (
|
110
|
tablename text NOT NULL,
|
111
|
xaxis text,
|
112
|
yaxis text,
|
113
|
agg text,
|
114
|
zaxis text,
|
115
|
type text,
|
116
|
tableorder integer NOT NULL
|
117
|
);
|
118
|
|
119
|
|
120
|
--
|
121
|
-- Name: category; Type: TABLE; Schema: public; Owner: dnet; Tablespace:
|
122
|
--
|
123
|
CREATE TABLE shadow.category (
|
124
|
id text NOT NULL,
|
125
|
name text,
|
126
|
context text
|
127
|
);
|
128
|
|
129
|
--
|
130
|
-- Name: claim; Type: TABLE; Schema: public; Owner: dnet; Tablespace:
|
131
|
--
|
132
|
|
133
|
CREATE TABLE shadow.claim (
|
134
|
id text NOT NULL,
|
135
|
date text ,
|
136
|
userid text
|
137
|
);
|
138
|
|
139
|
|
140
|
--
|
141
|
-- Name: context; Type: TABLE; Schema: public; Owner: dnet; Tablespace:
|
142
|
--
|
143
|
|
144
|
CREATE TABLE shadow.context (
|
145
|
id text NOT NULL,
|
146
|
name text
|
147
|
);
|
148
|
|
149
|
--
|
150
|
-- Name: organization; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace:
|
151
|
--
|
152
|
|
153
|
CREATE TABLE shadow.organization (
|
154
|
id text NOT NULL,
|
155
|
organization_datasources text NOT NULL,
|
156
|
organization_projects text NOT NULL,
|
157
|
name text,
|
158
|
country text,
|
159
|
websiteurl text,
|
160
|
deletedbyinference TEXT,
|
161
|
number integer DEFAULT 1 NOT NULL
|
162
|
);
|
163
|
|
164
|
|
165
|
|
166
|
--
|
167
|
-- Name: organization_datasources; Type: VIEW; Schema: shadow; Owner: sqoop
|
168
|
--
|
169
|
|
170
|
CREATE VIEW shadow.organization_datasources AS
|
171
|
SELECT datasource_organizations.organization AS id, datasource_organizations.id AS datasource FROM datasource_organizations;
|
172
|
|
173
|
--
|
174
|
-- Name: project_organizations; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace:
|
175
|
--
|
176
|
|
177
|
CREATE TABLE shadow.project_organizations (
|
178
|
id text NOT NULL,
|
179
|
organization text NOT NULL
|
180
|
);
|
181
|
|
182
|
|
183
|
--
|
184
|
-- Name: project_organizations; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace:
|
185
|
--
|
186
|
|
187
|
CREATE TABLE shadow.result_organizations (
|
188
|
id text NOT NULL,
|
189
|
organization text NOT NULL
|
190
|
);
|
191
|
|
192
|
|
193
|
--
|
194
|
-- Name: organization_projects; Type: VIEW; Schema: shadow; Owner: sqoop
|
195
|
--
|
196
|
|
197
|
CREATE VIEW shadow.organization_projects AS
|
198
|
SELECT project_organizations.id AS project, project_organizations.organization AS id FROM project_organizations;
|
199
|
|
200
|
--
|
201
|
-- Name: project; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace:
|
202
|
--
|
203
|
|
204
|
CREATE TABLE shadow.project (
|
205
|
id text NOT NULL,
|
206
|
project_organizations text NOT NULL,
|
207
|
project_results text NOT NULL,
|
208
|
acronym text ,
|
209
|
title text ,
|
210
|
funder text,
|
211
|
funding_lvl0 text,
|
212
|
funding_lvl1 text,
|
213
|
funding_lvl2 text,
|
214
|
funding_lvl3 text,
|
215
|
sc39 text,
|
216
|
type text,
|
217
|
url text,
|
218
|
start_year integer,
|
219
|
end_year integer,
|
220
|
duration integer,
|
221
|
haspubs text DEFAULT 'no'::text,
|
222
|
numpubs integer,
|
223
|
enddate text,
|
224
|
startdate text,
|
225
|
daysforlastpub integer,
|
226
|
delayedpubs integer,
|
227
|
callidentifier text,
|
228
|
code text,
|
229
|
ecarticle293 text,
|
230
|
sources text,
|
231
|
deletedbyinference TEXT,
|
232
|
number text
|
233
|
);
|
234
|
|
235
|
--
|
236
|
-- Name: result_projects; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace:
|
237
|
--
|
238
|
|
239
|
CREATE TABLE shadow.project_oids (
|
240
|
id text NOT NULL,
|
241
|
orid text
|
242
|
);
|
243
|
|
244
|
|
245
|
|
246
|
CREATE TABLE shadow.result_oids (
|
247
|
id text NOT NULL,
|
248
|
orid text
|
249
|
);
|
250
|
|
251
|
|
252
|
CREATE TABLE shadow.organization_oids (
|
253
|
id text NOT NULL,
|
254
|
orid text
|
255
|
);
|
256
|
|
257
|
|
258
|
CREATE TABLE shadow.datasource_oids (
|
259
|
id text NOT NULL,
|
260
|
orid text
|
261
|
);
|
262
|
|
263
|
-- CREATE TABLE shadow.person_oids (
|
264
|
-- id text NOT NULL,
|
265
|
-- orid text
|
266
|
-- );
|
267
|
|
268
|
|
269
|
CREATE TABLE shadow.project_keywords (
|
270
|
id text NOT NULL,
|
271
|
keyword text
|
272
|
);
|
273
|
|
274
|
|
275
|
CREATE TABLE shadow.project_subjects (
|
276
|
id text NOT NULL,
|
277
|
subject text
|
278
|
);
|
279
|
|
280
|
|
281
|
--ALTER TABLE shadow.result_projects OWNER TO sqoop;
|
282
|
|
283
|
CREATE TABLE shadow.project_results (
|
284
|
id text NOT NULL,
|
285
|
result text NOT NULL,
|
286
|
daysfromend integer
|
287
|
);
|
288
|
|
289
|
|
290
|
--
|
291
|
-- Name: result; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace:
|
292
|
--
|
293
|
|
294
|
CREATE TABLE shadow.result (
|
295
|
id text NOT NULL,
|
296
|
result_topics text NOT NULL,
|
297
|
result_languages text NOT NULL,
|
298
|
result_projects text NOT NULL,
|
299
|
result_datasources text NOT NULL,
|
300
|
result_classifications text NOT NULL,
|
301
|
result_infrastructures text NOT NULL,
|
302
|
result_claims text NOT NULL,
|
303
|
result_results text NOT NULL,
|
304
|
title text,
|
305
|
format text,
|
306
|
publisher text,
|
307
|
journal text,
|
308
|
year integer,
|
309
|
date text ,
|
310
|
access_mode text,
|
311
|
bestlicense text,
|
312
|
type text ,
|
313
|
embargo_end_date text,
|
314
|
delayed text,
|
315
|
authors integer,
|
316
|
source text,
|
317
|
deletedbyinference TEXT,
|
318
|
number integer DEFAULT 1 NOT NULL
|
319
|
);
|
320
|
|
321
|
|
322
|
|
323
|
--
|
324
|
-- Name: result_claims; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace:
|
325
|
--
|
326
|
|
327
|
CREATE TABLE shadow.result_claims (
|
328
|
id text NOT NULL,
|
329
|
claim text NOT NULL
|
330
|
);
|
331
|
|
332
|
CREATE TABLE shadow.result_citations (
|
333
|
id text NOT NULL,
|
334
|
result text NOT NULL
|
335
|
-- trust text,
|
336
|
-- provenance text,
|
337
|
-- citation text
|
338
|
);
|
339
|
|
340
|
|
341
|
--
|
342
|
-- Name: result_classifications; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace:
|
343
|
--
|
344
|
|
345
|
CREATE TABLE shadow.result_classifications (
|
346
|
id text NOT NULL,
|
347
|
type text NOT NULL
|
348
|
);
|
349
|
|
350
|
--
|
351
|
-- Name: result_concepts; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace:
|
352
|
--
|
353
|
|
354
|
CREATE TABLE shadow.result_concepts (
|
355
|
id text NOT NULL,
|
356
|
concept text NOT NULL
|
357
|
);
|
358
|
|
359
|
--
|
360
|
-- Name: result_languages; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace:
|
361
|
--
|
362
|
|
363
|
CREATE TABLE shadow.result_languages (
|
364
|
id text NOT NULL,
|
365
|
language text NOT NULL
|
366
|
);
|
367
|
|
368
|
|
369
|
--
|
370
|
-- Name: result_results; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace:
|
371
|
--
|
372
|
|
373
|
CREATE TABLE shadow.result_results (
|
374
|
id text NOT NULL,
|
375
|
result text NOT NULL
|
376
|
);
|
377
|
|
378
|
|
379
|
|
380
|
--
|
381
|
-- Name: result_topics; Type: TABLE; Schema: shadow; Owner: sqoop; Tablespace:
|
382
|
--
|
383
|
|
384
|
CREATE TABLE shadow.result_topics (
|
385
|
id text NOT NULL,
|
386
|
topic text
|
387
|
);
|
388
|
|
389
|
|
390
|
CREATE TABLE shadow.result_descriptions (
|
391
|
id text NOT NULL,
|
392
|
description text
|
393
|
);
|
394
|
|
395
|
--
|
396
|
-- DATASOURCE Extra Inserts
|
397
|
--
|
398
|
|
399
|
|
400
|
-- CREATE TABLE shadow.person (
|
401
|
-- id text NOT NULL,
|
402
|
-- person_results text NOT NULL,
|
403
|
-- firstname text,
|
404
|
-- lastname text,
|
405
|
-- fullname text ,
|
406
|
-- nationality text ,
|
407
|
-- email text,
|
408
|
-- phone text,
|
409
|
-- deletedbyinference TEXT,
|
410
|
-- number text
|
411
|
-- );
|
412
|
|
413
|
|
414
|
-- CREATE TABLE shadow.person_results (
|
415
|
-- id text NOT NULL,
|
416
|
-- result text NOT NULL
|
417
|
-- );
|
418
|
|
419
|
-- CREATE TABLE shadow.project_persons (
|
420
|
-- id text NOT NULL,
|
421
|
-- person text NOT NULL
|
422
|
-- );
|
423
|
|
424
|
CREATE TABLE shadow.result_pids (
|
425
|
id text NOT NULL,
|
426
|
type text ,
|
427
|
pid text
|
428
|
);
|
429
|
|
430
|
|
431
|
|
432
|
|
433
|
|
434
|
|
435
|
|
436
|
CREATE OR REPLACE FUNCTION shadow.extra_defaults_datasource()
|
437
|
RETURNS void AS
|
438
|
$BODY$
|
439
|
BEGIN
|
440
|
|
441
|
INSERT INTO "shadow".datasource (id,datasource_results,datasource_organizations,datasource_languages,datasource_topics,name,type,compatibility,number) (SELECT 'other','other','other','other','other','Other','Repository','unknown',1 WHERE NOT EXISTS (SELECT 1 FROM "shadow".datasource WHERE name='Unknown Repository'));
|
442
|
UPDATE "shadow".datasource SET name='Other' where name='Unknown Repository';
|
443
|
UPDATE "shadow".result_datasources SET datasource=(SELECT id FROM "shadow".datasource WHERE name='Other') WHERE datasource NOT IN (SELECT id FROM "shadow".datasource);
|
444
|
|
445
|
TRUNCATE TABLE "shadow".defaults;
|
446
|
INSERT INTO "shadow".defaults VALUES ('result', 'year', 'number', 'count', '', 'column', 1);
|
447
|
INSERT INTO "shadow".defaults VALUES ('project', 'funding_lvl1', 'number', 'count', '', 'column', 2);
|
448
|
INSERT INTO "shadow".defaults VALUES ('organization', 'country', 'number', 'count', '', 'column', 3);
|
449
|
INSERT INTO "shadow".defaults VALUES ('datasource', 'oa_compatible', 'number', 'count', '', 'column', 4);
|
450
|
|
451
|
UPDATE "shadow".datasource SET yearofvalidation=null WHERE yearofvalidation='-1';
|
452
|
|
453
|
|
454
|
UPDATE shadow.project SET funder='FCT' WHERE funder='Fundação para a Ciência e a Tecnologia, I.P.';
|
455
|
|
456
|
update shadow.datasource set harvested ='true' where datasource.id in ( select distinct d.id from datasource d, datasource_results dr where d.id=dr.id);
|
457
|
|
458
|
END
|
459
|
$BODY$
|
460
|
LANGUAGE plpgsql VOLATILE
|
461
|
COST 100;
|
462
|
ALTER FUNCTION shadow.extra_defaults_datasource()
|
463
|
OWNER TO sqoop;
|
464
|
|
465
|
|
466
|
--
|
467
|
-- Project Results Extra Inserts
|
468
|
--
|
469
|
|
470
|
CREATE OR REPLACE FUNCTION shadow.update_project_results()
|
471
|
RETURNS void AS
|
472
|
$BODY$
|
473
|
BEGIN
|
474
|
|
475
|
|
476
|
CREATE OR REPLACE VIEW shadow.project_results_publication AS
|
477
|
SELECT "shadow".result_projects.id AS result,
|
478
|
"shadow".result_projects.project AS project_results,
|
479
|
"shadow"."result"."date" as resultdate,
|
480
|
"shadow"."project"."enddate" as projectenddate,
|
481
|
"shadow".result_projects.daysfromend
|
482
|
as daysfromend FROM "shadow".result_projects,
|
483
|
"shadow".result,
|
484
|
"shadow".project
|
485
|
where "shadow".result_projects.id="shadow".result.result_projects
|
486
|
and "shadow".result.type='publication'
|
487
|
and "shadow".project.project_results= "shadow".result_projects.project;
|
488
|
|
489
|
END
|
490
|
$BODY$
|
491
|
LANGUAGE plpgsql VOLATILE
|
492
|
COST 100;
|
493
|
ALTER FUNCTION shadow.update_project_results()
|
494
|
OWNER TO sqoop;
|
495
|
|
496
|
|
497
|
|
498
|
--
|
499
|
-- Project Has Publications Extra Inserts
|
500
|
--
|
501
|
CREATE OR REPLACE FUNCTION shadow.project_has_pubs()
|
502
|
RETURNS void AS
|
503
|
$BODY$
|
504
|
BEGIN
|
505
|
|
506
|
|
507
|
CREATE OR REPLACE VIEW shadow.project_pub_count AS
|
508
|
SELECT count(*) AS count, project_results_publication.project_results
|
509
|
FROM shadow.project_results_publication
|
510
|
GROUP BY project_results_publication.project_results;
|
511
|
|
512
|
--HAS PUBS
|
513
|
UPDATE "shadow"."project" SET haspubs='yes' WHERE project_results in (select project_results from shadow.project_results_publication );
|
514
|
|
515
|
|
516
|
END
|
517
|
$BODY$
|
518
|
LANGUAGE plpgsql VOLATILE
|
519
|
COST 100;
|
520
|
ALTER FUNCTION shadow.project_has_pubs()
|
521
|
OWNER TO sqoop;
|
522
|
|
523
|
|
524
|
--
|
525
|
-- Project Publications Count Updates
|
526
|
--
|
527
|
|
528
|
|
529
|
CREATE OR REPLACE FUNCTION shadow.project_pubs_count()
|
530
|
RETURNS void AS
|
531
|
$BODY$
|
532
|
BEGIN
|
533
|
|
534
|
--COUNT PUBS
|
535
|
|
536
|
UPDATE "shadow"."project" SET numpubs=( SELECT count from shadow.project_pub_count
|
537
|
WHERE shadow.project_pub_count.project_results = shadow.project.project_results )
|
538
|
where "shadow"."project".project_results in ( SELECT "shadow".project_results_publication.project_results FROM shadow.project_results_publication );
|
539
|
|
540
|
|
541
|
END
|
542
|
$BODY$
|
543
|
LANGUAGE plpgsql VOLATILE
|
544
|
COST 100;
|
545
|
ALTER FUNCTION shadow.project_pubs_count()
|
546
|
OWNER TO sqoop;
|
547
|
|
548
|
|
549
|
|
550
|
--
|
551
|
-- Project Delayed Publications
|
552
|
--
|
553
|
|
554
|
CREATE OR REPLACE FUNCTION shadow.project_delayedpubs()
|
555
|
RETURNS void AS
|
556
|
$BODY$
|
557
|
BEGIN
|
558
|
--delayedpubs PUBS
|
559
|
|
560
|
create or replace view shadow.delayedpubs as SELECT count(*) , project_results from "shadow"."project_results_publication"
|
561
|
WHERE "shadow"."project_results_publication".daysfromend > 0 group by project_results;
|
562
|
|
563
|
UPDATE "shadow"."project" SET delayedpubs = (SELECT "shadow"."delayedpubs".count from "shadow"."delayedpubs"
|
564
|
WHERE "shadow"."delayedpubs".project_results=project.project_results ) where "shadow".project.project_results in ( select project_results from "shadow"."delayedpubs" );
|
565
|
|
566
|
|
567
|
END
|
568
|
$BODY$
|
569
|
LANGUAGE plpgsql VOLATILE
|
570
|
COST 100;
|
571
|
ALTER FUNCTION shadow.project_delayedpubs()
|
572
|
OWNER TO sqoop;
|
573
|
|
574
|
|
575
|
--
|
576
|
-- Project daysforlastpub
|
577
|
--
|
578
|
|
579
|
CREATE OR REPLACE FUNCTION shadow.project_daysforlastpub()
|
580
|
RETURNS void AS
|
581
|
$BODY$
|
582
|
BEGIN
|
583
|
|
584
|
|
585
|
--daysforlastpub
|
586
|
|
587
|
UPDATE "shadow"."project" SET daysforlastpub = (
|
588
|
SELECT max(daysfromend)
|
589
|
FROM "shadow"."project_results_publication" WHERE shadow.project.project_results = shadow.project_results_publication.project_results AND "shadow"."project_results_publication".daysfromend > 0 )
|
590
|
where "shadow".project.project_results in ( select project_results from "shadow"."delayedpubs" );
|
591
|
|
592
|
|
593
|
END
|
594
|
$BODY$
|
595
|
LANGUAGE plpgsql VOLATILE
|
596
|
COST 100;
|
597
|
ALTER FUNCTION shadow.project_daysforlastpub()
|
598
|
OWNER TO sqoop;
|
599
|
|
600
|
--
|
601
|
-- Project delayed
|
602
|
--
|
603
|
|
604
|
|
605
|
CREATE OR REPLACE FUNCTION shadow.project_delayed ()
|
606
|
RETURNS void AS
|
607
|
$BODY$
|
608
|
BEGIN
|
609
|
|
610
|
--delayed
|
611
|
|
612
|
UPDATE "shadow"."result" SET delayed = 'yes' WHERE result.id IN
|
613
|
(SELECT result from shadow.project_results_publication where daysfromend >0);
|
614
|
|
615
|
|
616
|
END
|
617
|
$BODY$
|
618
|
LANGUAGE plpgsql VOLATILE
|
619
|
COST 100;
|
620
|
ALTER FUNCTION shadow.project_delayed()
|
621
|
OWNER TO sqoop;
|
622
|
|
623
|
|
624
|
--
|
625
|
-- Cleaning Up Temps
|
626
|
--
|
627
|
CREATE OR REPLACE FUNCTION shadow.cleanTemps ()
|
628
|
RETURNS void AS
|
629
|
$BODY$
|
630
|
BEGIN
|
631
|
|
632
|
drop view if exists shadow.delayedpubs ;
|
633
|
drop view if exists shadow.project_pub_count ;
|
634
|
drop view if exists shadow.delayedpubs ;
|
635
|
|
636
|
drop view if exists shadow.project_results_publication ;
|
637
|
END
|
638
|
$BODY$
|
639
|
LANGUAGE plpgsql VOLATILE
|
640
|
COST 100;
|
641
|
ALTER FUNCTION shadow.cleanTemps()
|
642
|
OWNER TO sqoop;
|
643
|
|
644
|
|
645
|
---functions
|
646
|
|
647
|
--
|
648
|
-- Name: create_indexes(); Type: FUNCTION; Schema: shadow; Owner: sqoop
|
649
|
--
|
650
|
|
651
|
CREATE FUNCTION shadow.create_indexes() RETURNS void
|
652
|
LANGUAGE plpgsql
|
653
|
AS $$
|
654
|
|
655
|
BEGIN
|
656
|
|
657
|
CREATE INDEX datasource_datasource_languages ON "shadow".datasource USING btree (datasource_languages);
|
658
|
CREATE INDEX datasource_datasource_organizations ON "shadow".datasource USING btree (datasource_organizations);
|
659
|
CREATE INDEX datasource_datasource_results ON "shadow".datasource USING btree (datasource_results);
|
660
|
CREATE INDEX datasource_datasource_topics ON "shadow".datasource USING btree (datasource_topics);
|
661
|
CREATE INDEX datasource_id ON "shadow".datasource USING btree (id);
|
662
|
CREATE INDEX datasource_type ON "shadow".datasource USING btree (type);
|
663
|
CREATE INDEX datasource_name ON "shadow".datasource USING btree (name);
|
664
|
CREATE INDEX datasource_piwik_id ON "shadow".datasource USING btree (piwik_id);
|
665
|
CREATE INDEX result_access_mode ON "shadow".result USING btree (access_mode);
|
666
|
CREATE INDEX result_authors ON "shadow".result USING btree (authors);
|
667
|
CREATE INDEX result_id ON "shadow".result USING btree (id);
|
668
|
CREATE INDEX result_result_datasources ON "shadow".result USING btree (result_datasources);
|
669
|
CREATE INDEX result_result_languages ON "shadow".result USING btree (result_languages);
|
670
|
CREATE INDEX result_result_projects ON "shadow".result USING btree (result_projects);
|
671
|
CREATE INDEX result_result_topics ON "shadow".result USING btree (result_topics);
|
672
|
CREATE INDEX result_year ON "shadow".result USING btree (year);
|
673
|
CREATE INDEX result_date ON "shadow"."result" USING btree ("date");
|
674
|
CREATE INDEX result_type ON "shadow"."result" USING btree ("type");
|
675
|
|
676
|
|
677
|
CREATE INDEX project_acronym ON "shadow"."project" USING btree (acronym);
|
678
|
CREATE INDEX project_enddate ON "shadow"."project" USING btree (enddate);
|
679
|
CREATE INDEX project_id ON "shadow"."project" USING btree (id);
|
680
|
CREATE INDEX project_project_results ON "shadow"."project" USING btree (project_results);
|
681
|
CREATE INDEX project_results_result ON "shadow"."project_results" USING btree (result);
|
682
|
CREATE INDEX project_results_project ON "shadow"."project_results" USING btree (id);
|
683
|
|
684
|
CREATE INDEX result_oids_id ON "shadow".result_oids USING btree (id COLLATE pg_catalog."default");
|
685
|
CREATE INDEX result_oids_oid ON "shadow".result_oids USING btree(orid COLLATE pg_catalog."default");
|
686
|
|
687
|
CREATE INDEX result_pids_id ON "shadow".result_pids USING btree (id COLLATE pg_catalog."default");
|
688
|
CREATE INDEX result_pids_type ON "shadow".result_pids USING btree (type COLLATE pg_catalog."default");
|
689
|
CREATE INDEX result_pids_pid ON "shadow".result_pids USING btree(pid COLLATE pg_catalog."default");
|
690
|
|
691
|
|
692
|
CREATE INDEX datasource_oids_id ON "shadow".datasource_oids USING btree (id COLLATE pg_catalog."default");
|
693
|
CREATE INDEX datasource_oids_orid ON "shadow".datasource_oids USING btree(orid COLLATE pg_catalog."default");
|
694
|
|
695
|
|
696
|
|
697
|
CREATE INDEX datasource_lang_id
|
698
|
ON shadow.datasource_languages (id ASC NULLS LAST);
|
699
|
|
700
|
CREATE INDEX dtsrc_org_id
|
701
|
ON shadow.datasource_organizations
|
702
|
USING btree
|
703
|
(id COLLATE pg_catalog."default");
|
704
|
|
705
|
CREATE INDEX res_class_type
|
706
|
ON shadow.result_classifications
|
707
|
USING btree
|
708
|
(type COLLATE pg_catalog."default");
|
709
|
|
710
|
CREATE INDEX res_class_id
|
711
|
ON shadow.result_classifications
|
712
|
USING btree
|
713
|
(id COLLATE pg_catalog."default");
|
714
|
|
715
|
CREATE INDEX res_dtsrc_dtsrc
|
716
|
ON shadow.result_datasources
|
717
|
USING btree
|
718
|
(datasource COLLATE pg_catalog."default");
|
719
|
|
720
|
CREATE INDEX res_dtsrc_id
|
721
|
ON shadow.result_datasources
|
722
|
USING btree
|
723
|
(id COLLATE pg_catalog."default");
|
724
|
|
725
|
CREATE INDEX res_lang_lang
|
726
|
ON shadow.result_languages
|
727
|
USING btree
|
728
|
(language COLLATE pg_catalog."default");
|
729
|
|
730
|
CREATE INDEX org_id
|
731
|
ON shadow.organization
|
732
|
USING btree
|
733
|
(id COLLATE pg_catalog."default");
|
734
|
|
735
|
CREATE INDEX org_country
|
736
|
ON shadow.organization
|
737
|
USING btree
|
738
|
(country COLLATE pg_catalog."default");
|
739
|
|
740
|
CREATE INDEX org_dtsrc
|
741
|
ON shadow.organization
|
742
|
USING btree
|
743
|
(organization_datasources COLLATE pg_catalog."default");
|
744
|
|
745
|
CREATE INDEX org_proj
|
746
|
ON shadow.organization
|
747
|
USING btree
|
748
|
(organization_projects COLLATE pg_catalog."default");
|
749
|
|
750
|
CREATE INDEX proj_funder
|
751
|
ON shadow.project
|
752
|
USING btree
|
753
|
(funder COLLATE pg_catalog."default");
|
754
|
|
755
|
CREATE INDEX proj_title
|
756
|
ON shadow.project
|
757
|
USING btree
|
758
|
(title COLLATE pg_catalog."default");
|
759
|
|
760
|
CREATE INDEX proj_fndlvl0
|
761
|
ON shadow.project
|
762
|
USING btree
|
763
|
(funding_lvl0 COLLATE pg_catalog."default");
|
764
|
|
765
|
|
766
|
CREATE INDEX proj_fndlvl1
|
767
|
ON shadow.project
|
768
|
USING btree
|
769
|
(funding_lvl1 COLLATE pg_catalog."default");
|
770
|
|
771
|
CREATE INDEX proj_fndlvl2
|
772
|
ON shadow.project
|
773
|
USING btree
|
774
|
(funding_lvl2 COLLATE pg_catalog."default");
|
775
|
|
776
|
|
777
|
CREATE INDEX proj_org_org
|
778
|
ON shadow.project_organizations
|
779
|
USING btree
|
780
|
(organization COLLATE pg_catalog."default");
|
781
|
|
782
|
CREATE INDEX proj_org_id
|
783
|
ON shadow.project_organizations
|
784
|
USING btree
|
785
|
(id COLLATE pg_catalog."default");
|
786
|
|
787
|
|
788
|
|
789
|
|
790
|
|
791
|
|
792
|
|
793
|
CREATE INDEX res_res_id
|
794
|
ON shadow.result_results
|
795
|
USING btree
|
796
|
(id COLLATE pg_catalog."default");
|
797
|
|
798
|
|
799
|
|
800
|
CREATE INDEX res_res_res
|
801
|
ON shadow.result_results
|
802
|
USING btree
|
803
|
(result COLLATE pg_catalog."default");
|
804
|
|
805
|
CREATE INDEX res_lang_id
|
806
|
ON shadow.result_languages
|
807
|
USING btree
|
808
|
(id COLLATE pg_catalog."default");
|
809
|
CREATE INDEX res_conc_id
|
810
|
ON shadow.result_concepts
|
811
|
USING btree
|
812
|
(id COLLATE pg_catalog."default");
|
813
|
|
814
|
CREATE INDEX res_conc_conc
|
815
|
ON shadow.result_concepts
|
816
|
USING btree
|
817
|
(concept COLLATE pg_catalog."default");
|
818
|
|
819
|
CREATE INDEX res_class
|
820
|
ON shadow.result
|
821
|
USING btree
|
822
|
(result_classifications COLLATE pg_catalog."default");
|
823
|
|
824
|
CREATE INDEX res_bestlicense
|
825
|
ON shadow.result
|
826
|
USING btree
|
827
|
(bestlicense COLLATE pg_catalog."default");
|
828
|
|
829
|
CREATE INDEX proj_sc39
|
830
|
ON shadow.project
|
831
|
USING btree
|
832
|
(sc39 COLLATE pg_catalog."default");
|
833
|
CREATE INDEX proj_fndlvl3
|
834
|
ON shadow.project
|
835
|
USING btree
|
836
|
(funding_lvl3 COLLATE pg_catalog."default");
|
837
|
|
838
|
CREATE INDEX dtsrc_type
|
839
|
ON shadow.datasource
|
840
|
USING btree
|
841
|
(type COLLATE pg_catalog."default");
|
842
|
|
843
|
CREATE INDEX dtsrc_name
|
844
|
ON shadow.datasource
|
845
|
USING btree
|
846
|
(name COLLATE pg_catalog."default");
|
847
|
|
848
|
CREATE INDEX dtsrc_compatibility
|
849
|
ON shadow.datasource
|
850
|
USING btree
|
851
|
(compatibility COLLATE pg_catalog."default");
|
852
|
|
853
|
CREATE INDEX org_name
|
854
|
ON shadow.organization
|
855
|
USING btree
|
856
|
(name COLLATE pg_catalog."default");
|
857
|
|
858
|
CREATE INDEX dtsrc_org_org
|
859
|
ON shadow.datasource_organizations
|
860
|
USING btree
|
861
|
(organization COLLATE pg_catalog."default");
|
862
|
|
863
|
|
864
|
END;$$;
|
865
|
|
866
|
|
867
|
ALTER FUNCTION shadow.create_indexes() OWNER TO sqoop;
|
868
|
|
869
|
--
|
870
|
-- Name: create_views(); Type: FUNCTION; Schema: shadow; Owner: sqoop
|
871
|
--
|
872
|
|
873
|
CREATE or replace FUNCTION "shadow".create_views() RETURNS void
|
874
|
LANGUAGE plpgsql
|
875
|
AS $$
|
876
|
|
877
|
BEGIN
|
878
|
|
879
|
CREATE OR REPLACE VIEW "shadow".datasource_results as SELECT datasource as id , id as result FROM "shadow".result_datasources ;
|
880
|
|
881
|
CREATE OR REPLACE VIEW "shadow".organization_datasources as SELECT organization as id , id as datasource FROM "shadow".datasource_organizations ;
|
882
|
|
883
|
CREATE OR REPLACE VIEW "shadow".organization_projects as SELECT id as project, organization as id FROM "shadow".project_organizations ;
|
884
|
|
885
|
|
886
|
|
887
|
CREATE OR REPLACE VIEW shadow.result_projects AS SELECT shadow.project_results.result AS id,
|
888
|
shadow.project_results.id AS project, ( select to_date("shadow"."result"."date", 'YYYY-MM-DD')- to_date("shadow"."project"."enddate", 'YYYY-MM-DD')
|
889
|
from shadow.result, shadow.project where shadow.result.id = shadow.project_results.result
|
890
|
and shadow.project_results.id= shadow.project.id and shadow.result.type='publication' )
|
891
|
as daysfromend FROM shadow.project_results;
|
892
|
|
893
|
CREATE OR REPLACE VIEW "shadow".datasource_topics AS
|
894
|
SELECT distinct "shadow".datasource.id, "shadow".result_topics.topic
|
895
|
FROM "shadow".datasource, "shadow".datasource_results, "shadow".result, "shadow".result_topics
|
896
|
WHERE "shadow".datasource.datasource_results = "shadow".datasource_results.id AND "shadow".datasource_results.result = "shadow".result.id AND
|
897
|
"shadow".result_topics.id = "shadow".result.result_topics;
|
898
|
|
899
|
|
900
|
END;$$;
|
901
|
--
|
902
|
-- Name: create_charts(); Type: FUNCTION; Schema: shadow; Owner: sqoop
|
903
|
--
|
904
|
|
905
|
CREATE or replace FUNCTION "shadow".create_charts() RETURNS void
|
906
|
LANGUAGE plpgsql
|
907
|
AS $$
|
908
|
|
909
|
BEGIN
|
910
|
|
911
|
-- country nums
|
912
|
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;
|
913
|
|
914
|
-- country charts
|
915
|
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;
|
916
|
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;
|
917
|
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;
|
918
|
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;
|
919
|
|
920
|
-- datasource charts
|
921
|
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;
|
922
|
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;
|
923
|
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;
|
924
|
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;
|
925
|
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;
|
926
|
|
927
|
-- project charts
|
928
|
CREATE TABLE "shadow".chart_project_year AS SELECT p.id, r.year, count( distinct r.id) FROM "shadow".result r, "shadow".result_projects rp, "shadow".project p WHERE r.id=rp.id AND p.id=rp.project AND r.year>=p.start_year GROUP BY p.id, r.year;
|
929
|
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;
|
930
|
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;
|
931
|
|
932
|
-- funder nums
|
933
|
-- CREATE TABLE "shadow".numbers_funder AS SELECT funder, count(distinct r.id) AS pubstotal, count(distinct CASE WHEN r.bestlicense='Open Access' THEN r.id END) AS oapubs, count(distinct CASE WHEN r.bestlicense='Restricted' THEN r.id END) AS respubs, count(distinct CASE WHEN r.bestlicense='Embargo' THEN r.id END) AS embpubs, count(distinct p.id) AS projpubs, (SELECT count(distinct p2.id) FROM "shadow".project p2 WHERE p2.funder=p.funder GROUP BY p2.funder) AS projtotal FROM "shadow".project p, "shadow".project_results pr, "shadow".result r WHERE p.id=pr.id AND pr.result=r.id AND r.type='publication' GROUP BY funder ORDER BY funder;
|
934
|
|
935
|
-- funder charts
|
936
|
-- CREATE TABLE "shadow".chart_funder_year AS SELECT p.funder, r.year, count(distinct r.id) FROM "shadow".result r, "shadow".project_results pr, "shadow".project p WHERE r.id=pr.result AND pr.id=p.id AND r.type='publication' AND r.year >= 2007 AND r.year <= extract(YEAR from now()) GROUP BY p.funder, r.year ORDER BY p.funder, r.year;
|
937
|
-- CREATE TABLE "shadow".chart_funder_license AS SELECT p.funder, r.bestlicense, count(distinct r.id) from "shadow".result r, "shadow".project_results pr, "shadow".project p WHERE r.id=pr.result AND pr.id=p.id AND r.type='publication' GROUP BY p.funder, r.bestlicense ORDER BY p.funder, r.bestlicense;
|
938
|
-- CREATE TABLE "shadow".chart_funder_fp7 AS SELECT p.funder, r.year, count(distinct r.id) from "shadow".result r, "shadow".project_results pr, "shadow".project p, "shadow".project_results pr2, "shadow".project p2 WHERE r.id=pr.result AND pr.id=p.id AND pr2.result=r.id AND pr2.id=p2.id AND p2.funding_lvl0='FP7' AND r.year >= 2007 AND r.year <= extract(YEAR from now()) GROUP BY p.funder, r.year ORDER BY p.funder, r.year;
|
939
|
|
940
|
|
941
|
END;$$;
|
942
|
|
943
|
--
|
944
|
-- Name: create_charts(); Type: FUNCTION; Schema: shadow; Owner: sqoop
|
945
|
--
|
946
|
|
947
|
CREATE or replace FUNCTION "shadow".create_chart_indexes() RETURNS void
|
948
|
LANGUAGE plpgsql
|
949
|
AS $$
|
950
|
|
951
|
BEGIN
|
952
|
|
953
|
-- country nums
|
954
|
CREATE INDEX numbers_country_country ON "shadow".numbers_country USING btree(country);
|
955
|
|
956
|
-- country charts
|
957
|
CREATE INDEX chart_country_year_country ON "shadow".chart_country_year USING btree(country);
|
958
|
CREATE INDEX chart_country_datasources_country ON "shadow".chart_country_datasources USING btree(country);
|
959
|
CREATE INDEX chart_country_type_country ON "shadow".chart_country_type USING btree(country);
|
960
|
CREATE INDEX chart_country_fp7_country ON "shadow".chart_country_fp7 USING btree(country);
|
961
|
|
962
|
-- datasource
|
963
|
CREATE INDEX chart_datasource_type_datasource ON "shadow".chart_datasource_type USING btree(datasource);
|
964
|
CREATE INDEX chart_datasource_year_datasource ON "shadow".chart_datasource_year USING btree(datasource);
|
965
|
CREATE INDEX chart_datasource_funders_datasource ON "shadow".chart_datasource_funders USING btree(datasource);
|
966
|
CREATE INDEX chart_datasource_projects_pubs_datasource ON "shadow".chart_datasource_projects_pubs USING btree(datasource);
|
967
|
CREATE INDEX chart_datasource_projects_data_datasource ON "shadow".chart_datasource_projects_data USING btree(datasource);
|
968
|
|
969
|
-- project
|
970
|
CREATE INDEX chart_project_year_id ON "shadow".chart_project_year USING btree(id);
|
971
|
CREATE INDEX chart_project_license_id ON "shadow".chart_project_license USING btree(id);
|
972
|
CREATE INDEX chart_project_repos_id ON "shadow".chart_project_repos USING btree(id);
|
973
|
|
974
|
-- funder nums
|
975
|
-- CREATE INDEX numbers_funder_funder ON "shadow".numbers_funder USING btree(funder);
|
976
|
|
977
|
-- funder charts
|
978
|
-- CREATE INDEX chart_funder_year_funder ON "shadow".chart_funder_year USING btree(funder);
|
979
|
-- CREATE INDEX chart_funder_license_funder ON "shadow".chart_funder_license USING btree(funder);
|
980
|
|
981
|
|
982
|
END;$$;
|
983
|
|
984
|
--
|
985
|
-- Name: clean_tables(); Type: FUNCTION; Schema: shadow; Owner: sqoop
|
986
|
--
|
987
|
|
988
|
CREATE or replace FUNCTION "shadow".clean_tables() RETURNS void
|
989
|
LANGUAGE plpgsql
|
990
|
AS $$
|
991
|
BEGIN
|
992
|
|
993
|
CREATE TABLE "shadow".rd_distinct AS SELECT DISTINCT * FROM "shadow".result_datasources;
|
994
|
TRUNCATE "shadow".result_datasources;
|
995
|
INSERT INTO "shadow".result_datasources SELECT * FROM "shadow".rd_distinct ORDER BY datasource;
|
996
|
DROP TABLE "shadow".rd_distinct;
|
997
|
|
998
|
|
999
|
END;$$;
|
1000
|
|
1001
|
--DROP type if exists infra_report_rec cascade;
|
1002
|
|
1003
|
--CREATE TYPE infra_report_rec as
|
1004
|
--(Publications varchar(50), Open_Access_Publications varchar(50),
|
1005
|
--FP7_Publications varchar(50), FP7_Closed_Access_Publications varchar(50),
|
1006
|
--FP7_Open_Access_Publications varchar(50),
|
1007
|
--FP7_Restricted_Access_Publications varchar(50), FP7_Embargo_Publications varchar(50) );
|
1008
|
|
1009
|
--CREATE OR REPLACE FUNCTION shadow.getInfraReports()
|
1010
|
-- RETURNS infra_report_rec
|
1011
|
--AS
|
1012
|
-- $$
|
1013
|
--DECLARE
|
1014
|
-- result_record infra_report_rec;
|
1015
|
--BEGIN
|
1016
|
--
|
1017
|
-- SELECT count(*) INTO result_record.Publications FROM shadow.result where type='publication';
|
1018
|
-- SELECT count(*) INTO result_record.Open_Access_Publications FROM shadow.result WHERE bestlicense='Open Access' and type='publication';
|
1019
|
--
|
1020
|
--SELECT count (distinct result_projects.id) INTO result_record.FP7_Publications FROM shadow.result, shadow.result_projects, shadow.project
|
1021
|
--WHERE result.result_projects = result_projects.id and type='publication' and result_projects.project = project.id and funding_lvl0 = 'FP7';
|
1022
|
--
|
1023
|
--SELECT count (distinct shadow.result_projects.id)
|
1024
|
-- INTO result_record.FP7_Closed_Access_Publications
|
1025
|
-- FROM shadow.result,
|
1026
|
-- shadow.result_projects,
|
1027
|
-- shadow.project
|
1028
|
-- WHERE result.result_projects = result_projects.id
|
1029
|
-- AND result_projects.project = project.id
|
1030
|
-- AND funding_lvl0 = 'FP7'
|
1031
|
-- AND bestlicense='Closed Access'
|
1032
|
-- AND type='publication';
|
1033
|
--
|
1034
|
--
|
1035
|
--SELECT count(distinct result_projects.id) INTO result_record.FP7_Open_Access_Publications FROM shadow.result,
|
1036
|
-- shadow.result_projects, shadow.project
|
1037
|
-- WHERE result_projects = result_projects.id AND result_projects.project = project.id and type='publication' and funding_lvl0 = 'FP7' and bestlicense='Open Access';
|
1038
|
--
|
1039
|
--SELECT count(distinct result_projects.id) INTO result_record.FP7_Restricted_Access_Publications
|
1040
|
-- FROM shadow.result, shadow.result_projects, shadow.project
|
1041
|
-- WHERE result.result_projects=result_projects.id
|
1042
|
-- AND result_projects.project = project.id and funding_lvl0 = 'FP7' and bestlicense='Restricted' and type='publication';
|
1043
|
--
|
1044
|
--
|
1045
|
--SELECT count(distinct result_projects.id) INTO result_record.FP7_Embargo_Publications FROM shadow.result, shadow.result_projects, shadow.project
|
1046
|
--WHERE result.result_projects = result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'FP7' and bestlicense='Embargo' and type='publication';
|
1047
|
--
|
1048
|
--RETURN result_record;
|
1049
|
--
|
1050
|
--END
|
1051
|
--$$ LANGUAGE plpgsql;
|
1052
|
--
|
1053
|
--drop type if exists fp7_report_rec cascade;
|
1054
|
--
|
1055
|
--CREATE TYPE fp7_report_rec as
|
1056
|
--(FP7_Publications varchar(50),
|
1057
|
-- FP7_Projects varchar(50),
|
1058
|
-- FP7_SC39_Projects varchar(50),
|
1059
|
-- FP7_SC39_Publications varchar(50),
|
1060
|
-- FP7_SC39_Open_Access varchar(50));
|
1061
|
--
|
1062
|
--
|
1063
|
--CREATE OR REPLACE FUNCTION shadow.getFp7Reports()
|
1064
|
-- RETURNS fp7_report_rec
|
1065
|
--AS
|
1066
|
-- $$
|
1067
|
--
|
1068
|
--DECLARE
|
1069
|
-- result_record fp7_report_rec;
|
1070
|
--
|
1071
|
--BEGIN
|
1072
|
--
|
1073
|
----FP7 WITH PUBS
|
1074
|
--SELECT count(distinct project.id) into result_record.FP7_Publications FROM shadow.result, shadow.result_projects, shadow.project
|
1075
|
--WHERE result.result_projects = result_projects.id and type='publication'
|
1076
|
-- and result_projects.project = project.id and funding_lvl0='FP7' ;
|
1077
|
--
|
1078
|
--SELECT count(id) into result_record.FP7_Projects FROM shadow.project WHERE funding_lvl0 = 'FP7';
|
1079
|
-- SELECT count(number) into result_record.FP7_SC39_Projects from shadow.project where funding_lvl0='FP7' and sc39='yes';
|
1080
|
--
|
1081
|
--SELECT count(distinct project.id) into result_record.FP7_SC39_Publications FROM shadow.result, shadow.result_projects, shadow.project
|
1082
|
-- WHERE result_projects.project=project.id and funding_lvl0 = 'FP7' and sc39='yes' and result.result_projects = result_projects.id and type='publication';
|
1083
|
--
|
1084
|
--SELECT count(distinct result_projects.id) into result_record.FP7_SC39_Open_Access FROM shadow.result, shadow.result_projects, shadow.project
|
1085
|
-- WHERE result.result_projects = result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'FP7' and bestlicense='Open Access' and sc39='yes' and type='publication';
|
1086
|
--
|
1087
|
--RETURN result_record;
|
1088
|
--
|
1089
|
--END
|
1090
|
--$$ LANGUAGE plpgsql;
|
1091
|
--
|
1092
|
--
|
1093
|
--drop type wt_report_rec cascade;
|
1094
|
--
|
1095
|
--CREATE TYPE wt_report_rec as
|
1096
|
--(WT_Publications varchar(50),
|
1097
|
-- WT_Projects varchar(50),
|
1098
|
-- WT_Open_Access varchar(50),
|
1099
|
-- WT_Restricted_Access varchar(50),
|
1100
|
-- WT_Embargo varchar(50));
|
1101
|
--
|
1102
|
--
|
1103
|
--CREATE OR REPLACE FUNCTION shadow.getWTReports()
|
1104
|
-- RETURNS wt_report_rec
|
1105
|
--AS
|
1106
|
-- $$
|
1107
|
--
|
1108
|
--DECLARE
|
1109
|
-- result_record wt_report_rec;
|
1110
|
--
|
1111
|
--BEGIN
|
1112
|
--
|
1113
|
--SELECT count(distinct project.id) into result_record.WT_Publications FROM shadow.result, shadow.project, shadow.result_projects
|
1114
|
--where result_projects.project = project.id and project.funding_lvl0='WT' and result.result_projects = result_projects.id and type='publication';
|
1115
|
--
|
1116
|
--SELECT count(id) into result_record.WT_Projects FROM project WHERE funding_lvl0 = 'WT';
|
1117
|
--
|
1118
|
--SELECT count(distinct result_projects.id) into result_record.WT_Open_Access FROM shadow.result, shadow.result_projects, shadow.project WHERE result.result_projects= result_projects.id
|
1119
|
--AND result_projects.project = project.id and funding_lvl0 = 'WT' and bestlicense='Open Access' and type='publication';
|
1120
|
--
|
1121
|
--SELECT count(distinct result_projects.id) into result_record.WT_Restricted_Access FROM shadow.result, shadow.result_projects,
|
1122
|
--shadow.project WHERE result.result_projects = result_projects.id AND
|
1123
|
--result_projects.project = project.id and funding_lvl0 = 'WT' and
|
1124
|
--bestlicense='Restricted' and type='publication';
|
1125
|
--
|
1126
|
--SELECT count(distinct result_projects.id) into result_record.WT_Embargo FROM shadow.result, shadow.result_projects, shadow.project
|
1127
|
--WHERE result.result_projects=result_projects.id AND result_projects.project = project.id and funding_lvl0 = 'WT'
|
1128
|
--and bestlicense='Embargo' and type='publication';
|
1129
|
--
|
1130
|
--RETURN result_record;
|
1131
|
--
|
1132
|
--END
|
1133
|
--$$ LANGUAGE plpgsql;
|
1134
|
--
|
1135
|
--
|
1136
|
--
|
1137
|
--drop type if exists erc_report_rec cascade;
|
1138
|
--
|
1139
|
--CREATE TYPE erc_report_rec as
|
1140
|
--(ERC_Publications varchar(50),
|
1141
|
-- ERC_Projects varchar(50),
|
1142
|
-- ERC_Open_Access varchar(50),
|
1143
|
-- ERC_Restricted_Access varchar(50),
|
1144
|
-- ERC_Embargo varchar(50));
|
1145
|
--
|
1146
|
--
|
1147
|
--
|
1148
|
--CREATE OR REPLACE FUNCTION shadow.getERCReports()
|
1149
|
-- RETURNS erc_report_rec
|
1150
|
--AS
|
1151
|
-- $$
|
1152
|
--
|
1153
|
--DECLARE
|
1154
|
-- result_record erc_report_rec;
|
1155
|
--
|
1156
|
--BEGIN
|
1157
|
--
|
1158
|
--SELECT count(distinct project.id) into result_record.ERC_Publications FROM shadow.result, shadow.project, shadow.result_projects
|
1159
|
--where result_projects.project = project.id and project.funding_lvl2='ERC' and result.result_projects = result_projects.id and type='publication';
|
1160
|
--
|
1161
|
--SELECT count(id) into result_record.ERC_Projects FROM shadow.project WHERE funding_lvl2 = 'ERC';
|
1162
|
--
|
1163
|
--
|
1164
|
--SELECT count(distinct result_projects.id) into result_record.ERC_Open_Access FROM shadow.result,
|
1165
|
--shadow.result_projects, shadow.project WHERE result.result_projects= result_projects.id
|
1166
|
--AND result_projects.project = project.id and funding_lvl2 = 'ERC' and bestlicense='Open Access' and type='publication';
|
1167
|
--
|
1168
|
--
|
1169
|
--SELECT count(distinct result_projects.id) into result_record.ERC_Restricted_Access FROM shadow.result, shadow.result_projects, shadow.project WHERE
|
1170
|
-- result.result_projects = result_projects.id AND result_projects.project = project.id and funding_lvl2 = 'ERC' and bestlicense='Restricted' and type='publication';
|
1171
|
--
|
1172
|
--SELECT count(distinct result_projects.id) into result_record.ERC_Embargo FROM shadow.result, shadow.result_projects, shadow.project
|
1173
|
-- WHERE result.result_projects=result_projects.id AND result_projects.project = project.id and funding_lvl2 = 'ERC' and bestlicense='Embargo' and type='publication';
|
1174
|
--
|
1175
|
--
|
1176
|
--RETURN result_record;
|
1177
|
--
|
1178
|
--END
|
1179
|
--$$ LANGUAGE plpgsql;
|
1180
|
|
1181
|
-- sqoopQL database dump complete
|
1182
|
--
|