Skip to content

Commit 630488d

Browse files
committed
Fixing multi-dataset downloads
With the new site object there was a problem getting downloads for multiple datasets simultaneously. This fix adds a new method for ap.siteobject for datasetids as an int[]. This then passes through to the 01_datasetinfo file where we also improve handling of arrays in the siteobj subquery.
1 parent 72602ab commit 630488d

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

function/ap/siteobject.sql

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,24 @@ AS $function$
1818
GROUP BY sts.siteid, sts.sitename, sts.sitedescription, ST_AsGeoJSON(sts.geog,5,2),
1919
sts.area, sts.altitude, sts.notes, gpn.names;
2020
$function$;
21+
22+
CREATE OR REPLACE FUNCTION ap.siteobject(_siteid integer[])
23+
RETURNS TABLE(siteid integer, site jsonb)
24+
LANGUAGE sql
25+
AS $function$
26+
SELECT sts.siteid,
27+
jsonb_build_object( 'siteid', sts.siteid,
28+
'sitename', sts.sitename,
29+
'sitedescription', sts.sitedescription,
30+
'geography', ST_AsGeoJSON(sts.geog,5,2),
31+
'area', sts.area,
32+
'altitude', sts.altitude,
33+
'notes', sts.notes,
34+
'geopolitical', gpn.names) AS site
35+
FROM
36+
ndb.sites AS sts
37+
LEFT JOIN ap.geopolnames AS gpn ON gpn.siteid = sts.siteid
38+
WHERE sts.siteid = ANY(_siteid)
39+
GROUP BY sts.siteid, sts.sitename, sts.sitedescription, ST_AsGeoJSON(sts.geog,5,2),
40+
sts.area, sts.altitude, sts.notes, gpn.names;
41+
$function$;

function/doi/01_datasetinfo.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ WITH siteid AS (
1212
siteobj AS (
1313
SELECT *
1414
FROM
15-
ap.siteobject((SELECT siteid FROM siteid))
15+
ap.siteobject((SELECT array_agg(siteid) FROM siteid))
1616
)
1717
SELECT dts.datasetid,
1818
sts.site ||

0 commit comments

Comments
 (0)