Skip to content

Commit 66372b6

Browse files
committed
[*] improve Download chain sample
1 parent cf4c120 commit 66372b6

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

samples/Download.sql

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
-- Prepare the destination table 'location'
2+
CREATE TABLE IF NOT EXISTS city(
3+
city text,
4+
lat numeric,
5+
lng numeric,
6+
country text,
7+
iso2 text,
8+
admin_name text,
9+
capital text,
10+
population bigint,
11+
population_proper bigint);
12+
113
-- An enhanced example consisting of three tasks:
214
-- 1. Download text file from internet using BUILT-IN command
315
-- 2. Remove accents (diacritic signs) from letters using PROGRAM command (can be done with `unaccent` PostgreSQL extension)
@@ -24,7 +36,7 @@ BEGIN
2436
VALUES (v_task_id, 1,
2537
'{
2638
"workersnum": 1,
27-
"fileurls": ["https://www.cybertec-postgresql.com/secret/orte.txt"],
39+
"fileurls": ["https://simplemaps.com/static/data/country-cities/mt/mt.csv"],
2840
"destpath": "."
2941
}'::jsonb);
3042

@@ -40,7 +52,7 @@ BEGIN
4052
-- Under Windows we should call PowerShell instead of "uconv" with command:
4153
-- Set-content "orte_ansi.txt" ((Get-content "orte.txt").Normalize("FormD") -replace '\p{M}', '')
4254
INSERT INTO timetable.parameter (task_id, order_id, value)
43-
VALUES (v_task_id, 1, '["-x", "Latin-ASCII", "-o", "orte_ansi.txt", "orte.txt"]'::jsonb);
55+
VALUES (v_task_id, 1, '["-x", "Latin-ASCII", "-o", "mt_ansi.csv", "mt.csv"]'::jsonb);
4456

4557
RAISE NOTICE 'Step 2 completed. Unacent task added with ID: %', v_task_id;
4658

@@ -49,13 +61,17 @@ BEGIN
4961
VALUES (v_chain_id, 3, 'BUILTIN', 'CopyFromFile')
5062
RETURNING task_id INTO v_task_id;
5163

52-
-- Prepare the destination table 'location'
53-
CREATE TABLE IF NOT EXISTS location(name text);
54-
5564
-- Add the parameters for the download task. Execute client side COPY to 'location' from 'orte_ansi.txt'
5665
INSERT INTO timetable.parameter (task_id, order_id, value)
57-
VALUES (v_task_id, 1, '{"sql": "COPY location FROM STDIN", "filename": "orte_ansi.txt" }'::jsonb);
66+
VALUES (v_task_id, 1, '{"sql": "COPY city FROM STDIN (FORMAT csv, HEADER true)", "filename": "mt_ansi.csv" }'::jsonb);
5867

5968
RAISE NOTICE 'Step 3 completed. Import task added with ID: %', v_task_id;
69+
70+
INSERT INTO timetable.task (chain_id, task_order, kind, command, ignore_error, task_name)
71+
VALUES (v_chain_id, 4, 'PROGRAM', 'bash', TRUE, 'remove .csv')
72+
RETURNING task_id INTO v_task_id;
73+
74+
INSERT INTO timetable.parameter (task_id, order_id, value)
75+
VALUES (v_task_id, 1, '["-c", "rm *.csv"]'::jsonb);
6076
END;
61-
$$ LANGUAGE PLPGSQL;
77+
$$ LANGUAGE PLPGSQL;

0 commit comments

Comments
 (0)