move over parks
This commit is contained in:
parent
f1bb5512bf
commit
7495572192
3
Makefile
3
Makefile
|
@ -9,13 +9,14 @@ baseball.db: baseball-transformed.db sql/load.sql
|
|||
cat sql/load.sql | sqlite3 baseball.db
|
||||
sqlite3 baseball.db "VACUUM"
|
||||
|
||||
baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/franchiseseasons.sql sql/seasons.sql
|
||||
baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/franchiseseasons.sql sql/seasons.sql sql/parks.sql
|
||||
rm -f baseball-transformed.db
|
||||
cp baseball-raw.db baseball-transformed.db
|
||||
cat sql/franchises.sql | sqlite3 baseball-transformed.db
|
||||
cat sql/franchiseseasons.sql | sqlite3 baseball-transformed.db
|
||||
cat sql/awards.sql | sqlite3 baseball-transformed.db
|
||||
cat sql/seasons.sql | sqlite3 baseball-transformed.db
|
||||
cat sql/parks.sql | sqlite3 baseball-transformed.db
|
||||
|
||||
baseball-raw.db:
|
||||
rm -f baseball-raw.db
|
||||
|
|
20
sql/load.sql
20
sql/load.sql
|
@ -114,4 +114,24 @@ CREATE TABLE "people" (
|
|||
);
|
||||
|
||||
INSERT INTO "people" SELECT DISTINCT * FROM "transformed"."people";
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "parks" (
|
||||
"park.key" TEXT,
|
||||
"park.name" TEXT,
|
||||
"city" TEXT,
|
||||
"state" TEXT,
|
||||
"country" TEXT,
|
||||
PRIMARY KEY("park.key")
|
||||
);
|
||||
|
||||
insert into "parks" select distinct * from "transformed"."parks";
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "parkaliases" (
|
||||
"ID" TEXT,
|
||||
"alias" TEXT,
|
||||
PRIMARY KEY("ID","alias"),
|
||||
foreign key("ID") references "parks"("park.key")
|
||||
);
|
||||
|
||||
insert into "parkaliases" select distinct * from "transformed"."parkaliases";
|
||||
COMMIT;
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
begin;
|
||||
attach database 'baseball-raw.db' as 'raw';
|
||||
|
||||
create table if not exists "parkaliases" (
|
||||
"parkID" text,
|
||||
"alias" text,
|
||||
primary key("parkID","alias"),
|
||||
foreign key("parkID") references "parks"("park.key")
|
||||
"alias" text
|
||||
);
|
||||
|
||||
-- split aliases by semicolon
|
||||
with recursive aliases(parkid, alias) as (
|
||||
select "park.key", "park.alias" from parks
|
||||
select "park.key", "park.alias" from "raw"."parks"
|
||||
union
|
||||
select parkid, trim(substr(alias, instr(alias, ";") + 1)) as a
|
||||
from aliases
|
Loading…
Reference in New Issue