rename table
This commit is contained in:
parent
67fc105f66
commit
ec2a2057f2
4
Makefile
4
Makefile
|
@ -9,7 +9,7 @@ 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 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/teamcodes.sql
|
||||
baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/franchiseseasons.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
|
||||
rm -f baseball-transformed.db
|
||||
cp baseball-raw.db baseball-transformed.db
|
||||
cat sql/franchises.sql | sqlite3 baseball-transformed.db
|
||||
|
@ -28,7 +28,7 @@ baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/f
|
|||
cat sql/people.sql | sqlite3 baseball-transformed.db
|
||||
cat sql/seriespost.sql | sqlite3 baseball-transformed.db
|
||||
cat sql/fieldingofsplit.sql | sqlite3 baseball-transformed.db
|
||||
cat sql/teamcodes.sql | sqlite3 baseball-transformed.db
|
||||
cat sql/teams.sql | sqlite3 baseball-transformed.db
|
||||
|
||||
baseball-raw.db:
|
||||
rm -f baseball-raw.db
|
||||
|
|
20
sql/load.sql
20
sql/load.sql
|
@ -71,7 +71,7 @@ create table if not exists "franchiseseasons" (
|
|||
"teamIDretro" TEXT,
|
||||
PRIMARY KEY("year","franchise"),
|
||||
foreign key("year") references "seasons"("year"),
|
||||
foreign key("team") references "teamcodes"("ID"),
|
||||
foreign key("team") references "teams"("ID"),
|
||||
foreign key("franchise") references "franchises"("ID")
|
||||
);
|
||||
|
||||
|
@ -165,7 +165,7 @@ CREATE TABLE IF NOT EXISTS "salaries" (
|
|||
"salary" NUMERIC,
|
||||
PRIMARY KEY("year","player","team"),
|
||||
foreign key("player") references "people"("ID"),
|
||||
foreign key("team") references "teamcodes"("ID"),
|
||||
foreign key("team") references "teams"("ID"),
|
||||
foreign key("year") references "seasons"("year")
|
||||
);
|
||||
|
||||
|
@ -195,7 +195,7 @@ CREATE TABLE IF NOT EXISTS "batting" (
|
|||
"GIDP" NUMERIC,
|
||||
PRIMARY KEY("player","year","stint","team"),
|
||||
foreign key("player") references "people"("ID"),
|
||||
foreign key("team") references "teamcodes"("ID"),
|
||||
foreign key("team") references "teams"("ID"),
|
||||
foreign key("year") references "seasons"("year")
|
||||
);
|
||||
|
||||
|
@ -221,7 +221,7 @@ CREATE TABLE IF NOT EXISTS "fielding" (
|
|||
"ZR" NUMERIC,
|
||||
PRIMARY KEY("player","year","stint","team","POS"),
|
||||
foreign key("player") references "people"("ID"),
|
||||
foreign key("team") references "teamcodes"("ID"),
|
||||
foreign key("team") references "teams"("ID"),
|
||||
foreign key("year") references "seasons"("year")
|
||||
);
|
||||
|
||||
|
@ -259,7 +259,7 @@ CREATE TABLE IF NOT EXISTS "pitching" (
|
|||
"GIDP" NUMERIC,
|
||||
PRIMARY KEY("player","year","stint","team"),
|
||||
foreign key("player") references "people"("ID"),
|
||||
foreign key("team") references "teamcodes"("ID"),
|
||||
foreign key("team") references "teams"("ID"),
|
||||
foreign key("year") references "seasons"("year")
|
||||
);
|
||||
|
||||
|
@ -288,7 +288,7 @@ CREATE TABLE IF NOT EXISTS "appearances" (
|
|||
"G_pr" NUMERIC,
|
||||
PRIMARY KEY("year","team","player"),
|
||||
foreign key("player") references "people"("ID"),
|
||||
foreign key("team") references "teamcodes"("ID"),
|
||||
foreign key("team") references "teams"("ID"),
|
||||
foreign key("year") references "seasons"("year")
|
||||
);
|
||||
|
||||
|
@ -305,7 +305,7 @@ CREATE TABLE IF NOT EXISTS "homegames" (
|
|||
"attendance" NUMERIC,
|
||||
PRIMARY KEY("year","team","park"),
|
||||
foreign key("park") references "parks"("ID"),
|
||||
foreign key("team") references "teamcodes"("ID"),
|
||||
foreign key("team") references "teams"("ID"),
|
||||
foreign key("year") references "seasons"("year")
|
||||
);
|
||||
|
||||
|
@ -345,18 +345,18 @@ CREATE TABLE IF NOT EXISTS "fieldingofsplit" (
|
|||
"ZR" NUMERIC,
|
||||
PRIMARY KEY("player","year","stint","team","POS"),
|
||||
foreign key("player") references "people"("ID"),
|
||||
foreign key("team") references "teamcodes"("ID"),
|
||||
foreign key("team") references "teams"("ID"),
|
||||
foreign key("year") references "seasons"("year")
|
||||
);
|
||||
|
||||
insert into fieldingofsplit select distinct * from "transformed"."fieldingofsplit";
|
||||
|
||||
create table if not exists teamcodes (
|
||||
create table if not exists teams (
|
||||
"ID" text,
|
||||
"franchise" text,
|
||||
primary key("ID"),
|
||||
foreign key("franchise") references "franchises"("ID")
|
||||
);
|
||||
|
||||
insert into teamcodes select distinct * from "transformed"."teamcodes";
|
||||
insert into teams select distinct * from "transformed"."teams";
|
||||
COMMIT;
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
begin;
|
||||
attach database 'baseball-raw.db' as 'raw';
|
||||
create table if not exists teamcodes (
|
||||
create table if not exists teams (
|
||||
"ID" text,
|
||||
"franchise" text
|
||||
);
|
||||
|
||||
insert into teamcodes
|
||||
insert into teams
|
||||
select distinct teamid, franchid from "raw"."teams";
|
||||
|
||||
update teamcodes
|
||||
update teams
|
||||
set ID = 'WS9'
|
||||
where ID = 'WAS' and franchise = 'WAS';
|
||||
|
||||
update teamcodes
|
||||
update teams
|
||||
set ID = 'PHP'
|
||||
where ID = 'PH4' and franchise = 'PHQ';
|
||||
commit;
|
Loading…
Reference in New Issue