split parkaliases transform into own file
This commit is contained in:
parent
042ac946d7
commit
aba5b75ad5
3
Makefile
3
Makefile
|
@ -9,7 +9,7 @@ baseball.db: baseball-transformed.db sql/load.sql
|
||||||
cat sql/load.sql | sqlite3 baseball.db
|
cat sql/load.sql | sqlite3 baseball.db
|
||||||
sqlite3 baseball.db "VACUUM"
|
sqlite3 baseball.db "VACUUM"
|
||||||
|
|
||||||
baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/teamseasons.sql sql/seasons.sql sql/parks.sql sql/collegeplaying.sql sql/schools.sql sql/people.sql sql/salaries.sql sql/batting.sql sql/pitching.sql sql/fielding.sql sql/appearances.sql sql/homegames.sql sql/seriespost.sql sql/fieldingofsplit.sql sql/teams.sql sql/leagues.sql sql/managers.sql sql/awardsmanagers.sql sql/battingpost.sql sql/fieldingpost.sql sql/pitchingpost.sql sql/appearancespost.sql sql/awardsshareplayers.sql sql/yearlyawards.sql sql/halloffame.sql sql/halloffamereqs.sql sql/awardsplayers.sql
|
baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/teamseasons.sql sql/seasons.sql sql/parks.sql sql/collegeplaying.sql sql/schools.sql sql/people.sql sql/salaries.sql sql/batting.sql sql/pitching.sql sql/fielding.sql sql/appearances.sql sql/homegames.sql sql/seriespost.sql sql/fieldingofsplit.sql sql/teams.sql sql/leagues.sql sql/managers.sql sql/awardsmanagers.sql sql/battingpost.sql sql/fieldingpost.sql sql/pitchingpost.sql sql/appearancespost.sql sql/awardsshareplayers.sql sql/yearlyawards.sql sql/halloffame.sql sql/halloffamereqs.sql sql/awardsplayers.sql sql/parkaliases.sql
|
||||||
rm -f baseball-transformed.db
|
rm -f baseball-transformed.db
|
||||||
cp baseball-raw.db baseball-transformed.db
|
cp baseball-raw.db baseball-transformed.db
|
||||||
cat sql/franchises.sql | sqlite3 baseball-transformed.db
|
cat sql/franchises.sql | sqlite3 baseball-transformed.db
|
||||||
|
@ -41,6 +41,7 @@ baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/t
|
||||||
cat sql/halloffame.sql | sqlite3 baseball-transformed.db
|
cat sql/halloffame.sql | sqlite3 baseball-transformed.db
|
||||||
cat sql/halloffamereqs.sql | sqlite3 baseball-transformed.db
|
cat sql/halloffamereqs.sql | sqlite3 baseball-transformed.db
|
||||||
cat sql/awardsplayers.sql | sqlite3 baseball-transformed.db
|
cat sql/awardsplayers.sql | sqlite3 baseball-transformed.db
|
||||||
|
cat sql/parkaliases.sql | sqlite3 baseball-transformed.db
|
||||||
|
|
||||||
baseball-raw.db:
|
baseball-raw.db:
|
||||||
rm -f baseball-raw.db
|
rm -f baseball-raw.db
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
begin;
|
||||||
|
attach database 'baseball-raw.db' as 'raw';
|
||||||
|
|
||||||
|
create table if not exists "parkaliases" (
|
||||||
|
"parkID" text,
|
||||||
|
"alias" text
|
||||||
|
);
|
||||||
|
|
||||||
|
-- split aliases by semicolon
|
||||||
|
with recursive aliases(parkid, alias) as (
|
||||||
|
select "park.key", "park.alias" from "raw"."parks"
|
||||||
|
union
|
||||||
|
select parkid, trim(substr(alias, instr(alias, ";") + 1)) as a
|
||||||
|
from aliases
|
||||||
|
where a != ''
|
||||||
|
) insert into parkaliases
|
||||||
|
select parkid, case instr(alias, ";")
|
||||||
|
when 0 then alias
|
||||||
|
else trim(substr(alias, 1, instr(alias, ";") - 1)) end as a
|
||||||
|
from aliases
|
||||||
|
where a != '';
|
||||||
|
commit;
|
|
@ -1,25 +1,4 @@
|
||||||
begin;
|
begin;
|
||||||
attach database 'baseball-raw.db' as 'raw';
|
|
||||||
|
|
||||||
create table if not exists "parkaliases" (
|
|
||||||
"parkID" text,
|
|
||||||
"alias" text
|
|
||||||
);
|
|
||||||
|
|
||||||
-- split aliases by semicolon
|
|
||||||
with recursive aliases(parkid, alias) as (
|
|
||||||
select "park.key", "park.alias" from "raw"."parks"
|
|
||||||
union
|
|
||||||
select parkid, trim(substr(alias, instr(alias, ";") + 1)) as a
|
|
||||||
from aliases
|
|
||||||
where a != ''
|
|
||||||
) insert into parkaliases
|
|
||||||
select parkid, case instr(alias, ";")
|
|
||||||
when 0 then alias
|
|
||||||
else trim(substr(alias, 1, instr(alias, ";") - 1)) end as a
|
|
||||||
from aliases
|
|
||||||
where a != '';
|
|
||||||
|
|
||||||
alter table parks drop column "park.alias";
|
alter table parks drop column "park.alias";
|
||||||
|
|
||||||
-- insert some missing parks
|
-- insert some missing parks
|
||||||
|
|
Loading…
Reference in New Issue