forked from AtlasOfLivingAustralia/image-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export-functions.sql
68 lines (65 loc) · 1.79 KB
/
export-functions.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
62
63
64
65
66
67
68
CREATE OR REPLACE FUNCTION export_dataset(uid varchar) RETURNS void AS $$
DECLARE
output_file CONSTANT varchar := CONCAT(CONCAT( '/data/image-service/exports/images-export-', uid), '.csv');
BEGIN
EXECUTE format ('
COPY
(
select
image_identifier as "imageID",
original_filename as "identifier",
audience,
contributor,
created,
creator,
description,
mime_type as "format",
license,
publisher,
dc_references as "references",
rights_holder as "rightsHolder",
source,
title,
type
from image i
where data_resource_uid = %L
)
TO %L (FORMAT CSV)'
, uid, output_file);
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION export_dataset_mapping(uid varchar) RETURNS void AS $$
DECLARE
output_file CONSTANT varchar := CONCAT(CONCAT( '/data/image-service/exports/images-mapping-', uid), '.csv');
BEGIN
EXECUTE format ('
COPY
(
select
image_identifier as "imageID",
original_filename as "url"
from image i
where data_resource_uid = %L
)
TO %L (FORMAT CSV)'
, uid, output_file);
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION export_mapping() RETURNS void AS $$
DECLARE
output_file CONSTANT varchar := '/data/image-service/exports/images-mapping.csv';
BEGIN
EXECUTE format ('
COPY
(
select
data_resource_uid,
image_identifier as "imageID",
original_filename as "url"
from image i
where data_resource_uid is NOT NULL
)
TO %L (FORMAT CSV)'
, output_file);
END;
$$ LANGUAGE plpgsql;