Project

General

Profile

1
SELECT * FROM (
2
	SELECT
3
		(array_agg(DISTINCT o.country))[1]      AS country,
4
		(array_agg(DISTINCT o.legalname))[1]    AS organization,
5
		d.id                                    AS repoid,
6
		d.officialname                          AS reponame,
7
		d.englishname                           AS othername,
8
		d.namespaceprefix                       AS repoprefix,
9
		d.websiteurl                            AS repourl,
10
		a.id                                    AS id,
11
		a.active                                AS active,
12
		a.protocol                              AS protocol,
13
		a.typology                              AS type,
14
		a.compatibility                         AS compliance,
15
		CASE
16
			WHEN (a.last_aggregation_date IS NOT NULL) THEN to_char(a.last_aggregation_date, 'YYYY-MM-DD')
17
			WHEN (a.last_download_date IS NOT NULL) THEN to_char(a.last_download_date, 'YYYY-MM-DD')
18
			ELSE ''
19
		END AS aggrdate,
20
		CASE
21
			WHEN (a.last_aggregation_total IS NOT NULL) THEN to_char(a.last_aggregation_total, '')
22
			WHEN (a.last_download_total IS NOT NULL) THEN to_char(a.last_download_total, '')
23
			ELSE '0'
24
		END AS aggrtotal
25
	FROM
26
		api a
27
		LEFT OUTER JOIN datasources d               ON (a.datasource = d.id)
28
		LEFT OUTER JOIN datasource_organization dao ON (d.id = dao.datasource)
29
		LEFT OUTER JOIN organizations o             ON (dao.organization = o.id)
30
		GROUP BY
31
			d.id, d.officialname, d.englishname, d.namespaceprefix, d.websiteurl,
32
			a.id, a.active, a.protocol, a.typology, a.compatibility,
33
			a.last_aggregation_date, a.last_download_date,
34
			a.last_aggregation_total, a.last_download_total
35
) AS t WHERE
36
	$if(field)$
37
		$field$ = $delimeter$$value$$delimeter$
38
	$else$
39
		repoid ILIKE '%$value$%' 
40
		OR reponame ILIKE '%$value$%'
41
		OR othername ILIKE '%$value$%'
42
		OR repoprefix ILIKE '%$value$%' 
43
		OR repourl ILIKE '%$value$%' 
44
		OR organization ILIKE '%$value$%' 
45
	$endif$
46

    
47

    
(15-15/21)