-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscieloPages-reprodux.sql
61 lines (53 loc) · 1.96 KB
/
scieloPages-reprodux.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
CREATE VIEW report.c04_issues_listpervol AS
SELECT issn, year, volume,
array_to_string(array_agg(issue ORDER BY lpad0(issue)),'; ') as issues_txt,
to_jsonb( array_agg(issue ORDER BY lpad0(issue)) ) as issues_json
FROM article_issue_count
GROUP BY 1,2,3
ORDER BY 1, 2 DESC, 3 DESC
;
/**
* Issues script dataset and structure reproduction.
* SciELO script name: sci_issues(pid)
* Main SQL sources: article_issue_count
* Example for ISSN 0074-0276: http://www.scielo.br/scielo.php?script=sci_issues&pid=0074-0276
* @param issn
* @return relatório XHTML com mesma organização visual que a página SciELO.
*/
CREATE or replace FUNCTION report.c04_sci_issues(issnl integer) RETURNS xml AS $func$
SELECT
xmlelement(name section, xmlattributes('report' as class),
xmlelement(name header, xmlelement(name h1, name), xmlelement(
name p,
xmlelement( name b, 'ISSN-L '|| issn.cast(issn.n2c($1)) ),
'. ISSNs:'|| (issn.tservice_jspack(issn,'n2ns')->>'result')::text
)
),
xmlelement(name table, xmlattributes('1' as border),
xmlelement(name tr,
xmlelement(name th,'year'), xmlelement(name th,'volume'), xmlelement(name th,'issues')
), -- each th
(SELECT xmlagg(
xmlelement(name tr,
xmlelement(name td,year), xmlelement(name td,volume), xmlelement(name td,issues_txt)
)) -- xmlagg
FROM (SELECT * FROM report.c04_issues_listpervol ORDER BY year DESC, volume DESC) t
WHERE issn=$1
) -- select
)
) FROM journal
WHERE issn=$1
;
$func$ LANGUAGE SQL IMMUTABLE;
----------
-----
-- funções para a API
CREATE or replace FUNCTION c01_issues_json(int) RETURNS jsonB AS $func$
-- ex. select c01_issues_json(74027)
SELECT to_jsonb(array_agg(to_jsonb(t)))
FROM (
SELECT year, volume, issues_json as issues -- falta expandir issues em objetos
FROM report.c04_issues_listpervol
WHERE issn=$1
) t;
$func$ LANGUAGE SQL IMMUTABLE;