1
|
--WITH RECURSIVE fundingtree(id, parent_id, payload, depth)
|
2
|
--AS (
|
3
|
-- SELECT f.id,
|
4
|
-- ff.funding1,
|
5
|
-- '{"funding_level_0":{"class":"' || f.semanticclass || '", "id":"' || f.id || '", "description":"' || f.description || '", "name":"' || f.name || '", "parent":{}}}',
|
6
|
-- 1
|
7
|
-- FROM fundings f LEFT OUTER JOIN funding_funding ff ON f.id = ff.funding1
|
8
|
-- WHERE ff.funding2 IS NULL
|
9
|
-- UNION
|
10
|
-- SELECT f1.id,
|
11
|
-- ff.funding2,
|
12
|
-- '{"funding_level_'||depth||'":{"class":"' || f1.semanticclass || '", "id":"' || f1.id || '", "description":"' || f1.description || '", "name":"' || f1.name || '", "parent":'|| ft.payload ||'}}',
|
13
|
-- ft.depth + 1
|
14
|
-- FROM funding_funding ff, fundingtree ft, fundings f2, fundings f1
|
15
|
-- WHERE ft.id = ff.funding2 AND f2.id = ft.id AND ff.funding1 = f1.id AND depth <= 10)
|
16
|
|
17
|
SELECT p.id as projectid,
|
18
|
p.code as code,
|
19
|
p.websiteurl as websiteurl,
|
20
|
p.acronym as acronym,
|
21
|
p.title as title,
|
22
|
p.startdate as startdate,
|
23
|
p.enddate as enddate,
|
24
|
p.call_identifier as callidentifier,
|
25
|
p.keywords as keywords,
|
26
|
p.duration as duration,
|
27
|
p.ec_sc39 as ecsc39,
|
28
|
p.oa_mandate_for_publications as oamandatepublications,
|
29
|
p.ec_article29_3 as ecarticle29_3,
|
30
|
p.dateofcollection as dateofcollection,
|
31
|
p.inferred as inferred,
|
32
|
p.deletedbyinference as deletedbyinference,
|
33
|
p.trust as trust,
|
34
|
p.inferenceprovenance as inferenceprovenance,
|
35
|
p.optional1 as optional1,
|
36
|
p.optional2 as optional2,
|
37
|
p.jsonextrainfo as jsonextrainfo,
|
38
|
dc.id as collectedfromid,
|
39
|
dc.officialname as collectedfromname,
|
40
|
|
41
|
cc.code || '@@@' || cc.name || '@@@' || cs.code || '@@@' || cs.name as contracttype,
|
42
|
pac.code || '@@@' || pac.name || '@@@' || pas.code || '@@@' || pas.name as provenanceaction,
|
43
|
|
44
|
array_agg(DISTINCT i.pid || '###' || idc.code || '@@@' || idc.name || '@@@' || ids.code || '@@@' || ids.name) as pid,
|
45
|
array_agg(DISTINCT s.name || '###' || sc.code || '@@@' || sc.name || '@@@' || ss.code || '@@@' || ss.name) as subjects,
|
46
|
|
47
|
array_agg(fp.path) as fundingtree
|
48
|
|
49
|
FROM projects p
|
50
|
left outer join class cc on (cc.code = p.contracttypeclass)
|
51
|
left outer join scheme cs on (cs.code = p.contracttypescheme)
|
52
|
|
53
|
left outer join class pac on (pac.code = p.provenanceactionclass)
|
54
|
left outer join scheme pas on (pas.code = p.provenanceactionscheme)
|
55
|
|
56
|
left outer join projectpids pp on (pp.project = p.id)
|
57
|
left outer join identities i on (i.pid = pp.pid)
|
58
|
left outer join class idc on (idc.code = i.issuertypeclass)
|
59
|
left outer join scheme ids on (ids.code = i.issuertypescheme)
|
60
|
|
61
|
left outer join datasources dc on (dc.id = p.collectedfrom)
|
62
|
|
63
|
left outer join project_fundingpath pf on (pf.project = p.id)
|
64
|
left outer join fundingpaths fp on (fp.id = pf.funding)
|
65
|
|
66
|
left outer join project_subject ps on (ps.project = p.id)
|
67
|
left outer join subjects s on (s.id = ps.subject)
|
68
|
|
69
|
left outer join class sc on (sc.code = s.semanticclass)
|
70
|
left outer join scheme ss on (ss.code = s.semanticscheme)
|
71
|
|
72
|
GROUP BY
|
73
|
p.id,
|
74
|
p.code,
|
75
|
p.websiteurl,
|
76
|
p.acronym,
|
77
|
p.title,
|
78
|
p.startdate,
|
79
|
p.enddate,
|
80
|
p.call_identifier,
|
81
|
p.keywords,
|
82
|
p.duration,
|
83
|
p.ec_sc39,
|
84
|
p.oa_mandate_for_publications,
|
85
|
p.ec_article29_3,
|
86
|
p.dateofcollection,
|
87
|
p.inferred,
|
88
|
p.deletedbyinference,
|
89
|
p.trust,
|
90
|
p.inferenceprovenance,
|
91
|
dc.id,
|
92
|
dc.officialname,
|
93
|
cc.code, cc.name, cs.code, cs.name,
|
94
|
pac.code, pac.name, pas.code, pas.name
|
95
|
|