Revision 48139
Added by Alessia Bardi almost 7 years ago
queryProjects.sql | ||
---|---|---|
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 || '###' || i.issuertypeclass) 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 |
|
|
59 |
left outer join datasources dc on (dc.id = p.collectedfrom) |
|
60 |
|
|
61 |
left outer join project_fundingpath pf on (pf.project = p.id) |
|
62 |
left outer join fundingpaths fp on (fp.id = pf.funding) |
|
63 |
|
|
64 |
left outer join project_subject ps on (ps.project = p.id) |
|
65 |
left outer join subjects s on (s.id = ps.subject) |
|
66 |
|
|
67 |
left outer join class sc on (sc.code = s.semanticclass) |
|
68 |
left outer join scheme ss on (ss.code = s.semanticscheme) |
|
69 |
|
|
70 |
GROUP BY |
|
71 |
p.id, |
|
72 |
p.code, |
|
73 |
p.websiteurl, |
|
74 |
p.acronym, |
|
75 |
p.title, |
|
76 |
p.startdate, |
|
77 |
p.enddate, |
|
78 |
p.call_identifier, |
|
79 |
p.keywords, |
|
80 |
p.duration, |
|
81 |
p.ec_sc39, |
|
82 |
p.oa_mandate_for_publications, |
|
83 |
p.ec_article29_3, |
|
84 |
p.dateofcollection, |
|
85 |
p.inferred, |
|
86 |
p.deletedbyinference, |
|
87 |
p.trust, |
|
88 |
p.inferenceprovenance, |
|
89 |
dc.id, |
|
90 |
dc.officialname, |
|
91 |
cc.code, cc.name, cs.code, cs.name, |
|
92 |
pac.code, pac.name, pas.code, pas.name |
|
93 |
|
|
1 |
SELECT * |
|
2 |
FROM projects_mv |
Also available in: Unified diff
integrated (hopefully) all required changes from dnet40