-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathimport.sql
More file actions
65 lines (57 loc) · 877 Bytes
/
import.sql
File metadata and controls
65 lines (57 loc) · 877 Bytes
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
.mode csv
.import meteorites.csv temp
--> Set empty values to NULL
UPDATE "temp"
SET
"mass" = NULL
WHERE
"mass" = ''
OR "mass" IS NULL;
UPDATE "temp"
SET
"year" = NULL
WHERE
"year" = ''
OR "year" IS NULL;
UPDATE "temp"
SET
"lat" = NULL
WHERE
"lat" = ''
OR "lat" IS NULL;
UPDATE "temp"
SET
"long" = NULL
WHERE
"long" = ''
OR "long" IS NULL;
--> Round certain columns to two decimal places
UPDATE "temp"
SET
"mass" = ROUND("mass", 2),
"lat" = ROUND("lat", 2),
"long" = ROUND("long", 2);
--> Delete rows with nametype 'Relict'
DELETE FROM "temp"
WHERE
nametype = 'Relict';
--> Create the 'meteorites' table with new_order column
CREATE TABLE
meteorites AS
SELECT
ROW_NUMBER() OVER (
ORDER BY
"year",
"name"
) AS id,
"name",
"class",
"mass",
"discovery",
"year",
"lat",
"long"
FROM
"temp";
--> Drop the temporary table
DROP TABLE "temp";