-
Notifications
You must be signed in to change notification settings - Fork 1
/
imported_data.sql
61 lines (51 loc) · 1.59 KB
/
imported_data.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
-- create column entries identical to the country csv file
-- import data from country csv file (import from table plus literally right click & import)
-- create column entries identical to the cities csv file
-- import data from cities csv file
-- create cities table
--create countries table
-- write query to copy data from imported over to the desired countries table format
-- write query to copy data from imported over to the desired cities table format
DROP TABLE IF EXISTS countries_import;
CREATE TABLE countries_import (
abbrev TEXT NOT NULL,
country TEXT NOT NULL
);
DROP TABLE IF EXISTS cities_import;
CREATE TABLE cities_import (
country TEXT NOT NULL,
accent_city TEXT NOT NULL,
population INTEGER,
latitude FLOAT,
longitude FLOAT
);
DROP TABLE IF EXISTS countries;
CREATE TABLE countries (
id INTEGER PRIMARY KEY AUTOINCREMENT,
country TEXT NOT NULL,
visited BOOLEAN DEFAULT false,
would_visit BOOLEAN
);
ALTER TABLE "countries"
ADD COLUMN "blacklisted" Boolean DEFAULT false;
INSERT INTO countries (country)
SELECT country
FROM countries_import;
DROP TABLE IF EXISTS cities;
CREATE TABLE cities (
id INTEGER PRIMARY KEY AUTOINCREMENT,
city TEXT NOT NULL,
country_id INTEGER,
visited BOOLEAN DEFAULT false,
would_visit BOOLEAN
);
INSERT INTO cities (city, country_id)
SELECT accent_city, countries.id
FROM cities_import
JOIN countries ON countries.country = cities_import.country;
CREATE UNIQUE INDEX idx_countries_country
ON countries (country);
CREATE INDEX idx_cities_city
ON cities (city);
CREATE INDEX idx_cites_country_id
ON cities (country_id);