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
+
1
13
-- An enhanced example consisting of three tasks:
2
14
-- 1. Download text file from internet using BUILT-IN command
3
15
-- 2. Remove accents (diacritic signs) from letters using PROGRAM command (can be done with `unaccent` PostgreSQL extension)
24
36
VALUES (v_task_id, 1 ,
25
37
' {
26
38
"workersnum": 1,
27
- "fileurls": ["https://www.cybertec-postgresql. com/secret/orte.txt "],
39
+ "fileurls": ["https://simplemaps. com/static/data/country-cities/mt/mt.csv "],
28
40
"destpath": "."
29
41
}' ::jsonb);
30
42
40
52
-- Under Windows we should call PowerShell instead of "uconv" with command:
41
53
-- Set-content "orte_ansi.txt" ((Get-content "orte.txt").Normalize("FormD") -replace '\p{M}', '')
42
54
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);
44
56
45
57
RAISE NOTICE ' Step 2 completed. Unacent task added with ID: %' , v_task_id;
46
58
@@ -49,13 +61,17 @@ BEGIN
49
61
VALUES (v_chain_id, 3 , ' BUILTIN' , ' CopyFromFile' )
50
62
RETURNING task_id INTO v_task_id;
51
63
52
- -- Prepare the destination table 'location'
53
- CREATE TABLE IF NOT EXISTS location(name text );
54
-
55
64
-- Add the parameters for the download task. Execute client side COPY to 'location' from 'orte_ansi.txt'
56
65
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);
58
67
59
68
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);
60
76
END;
61
- $$ LANGUAGE PLPGSQL;
77
+ $$ LANGUAGE PLPGSQL;
0 commit comments