move postseasons tables

This commit is contained in:
Nick Griffey 2024-01-28 00:09:06 -06:00
parent 8539a3f0af
commit d8c91e3909
9 changed files with 134 additions and 100 deletions

View File

@ -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 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
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
@ -32,6 +32,10 @@ baseball-transformed.db: baseball-raw.db sql/awards.sql sql/franchises.sql sql/t
cat sql/leagues.sql | sqlite3 baseball-transformed.db cat sql/leagues.sql | sqlite3 baseball-transformed.db
cat sql/managers.sql | sqlite3 baseball-transformed.db cat sql/managers.sql | sqlite3 baseball-transformed.db
cat sql/awardsmanagers.sql | sqlite3 baseball-transformed.db cat sql/awardsmanagers.sql | sqlite3 baseball-transformed.db
cat sql/fieldingpost.sql | sqlite3 baseball-transformed.db
cat sql/battingpost.sql | sqlite3 baseball-transformed.db
cat sql/pitchingpost.sql | sqlite3 baseball-transformed.db
cat sql/appearancespost.sql | sqlite3 baseball-transformed.db
baseball-raw.db: baseball-raw.db:
rm -f baseball-raw.db rm -f baseball-raw.db

19
sql/appearancespost.sql Normal file
View File

@ -0,0 +1,19 @@
begin;
attach database 'baseball-raw.db' as 'raw';
create table if not exists appearancespost (
"year" numeric,
"player" text,
"team" text
);
insert into appearancespost
select distinct yearID, playerID, teamID
from 'raw'.battingpost
union
select distinct yearID, playerID, teamID
from 'raw'.pitchingpost
union
select distinct yearID, playerID, teamID
from 'raw'.fieldingpost;
commit;

4
sql/battingpost.sql Normal file
View File

@ -0,0 +1,4 @@
begin;
alter table battingpost drop column "lgID";
alter table battingpost drop column "teamID";
commit;

4
sql/fieldingpost.sql Normal file
View File

@ -0,0 +1,4 @@
begin;
alter table fieldingpost drop column "lgID";
alter table fieldingpost drop column "teamID";
commit;

View File

@ -1,32 +0,0 @@
begin;
CREATE TABLE IF NOT EXISTS "pk_battingpost" (
"yearID" NUMERIC,
"round" NUMERIC,
"playerID" TEXT,
"teamID" TEXT,
"lgID" TEXT,
"G" NUMERIC,
"AB" NUMERIC,
"R" NUMERIC,
"H" NUMERIC,
"2B" NUMERIC,
"3B" NUMERIC,
"HR" NUMERIC,
"RBI" NUMERIC,
"SB" NUMERIC,
"CS" NUMERIC,
"BB" NUMERIC,
"SO" NUMERIC,
"IBB" NUMERIC,
"HBP" NUMERIC,
"SH" NUMERIC,
"SF" NUMERIC,
"GIDP" NUMERIC,
PRIMARY KEY("yearID","playerID","round"),
foreign key("playerID") references "people"("playerID")
);
INSERT INTO "pk_battingpost" SELECT DISTINCT * FROM "battingpost";
DROP TABLE "battingpost";
ALTER TABLE "pk_battingpost" RENAME TO "battingpost";
commit;

View File

@ -1,27 +0,0 @@
BEGIN;
CREATE TABLE IF NOT EXISTS "pk_fieldingpost" (
"playerID" TEXT,
"yearID" NUMERIC,
"teamID" TEXT,
"lgID" TEXT,
"round" NUMERIC,
"POS" TEXT,
"G" NUMERIC,
"GS" NUMERIC,
"InnOuts" NUMERIC,
"PO" NUMERIC,
"A" NUMERIC,
"E" NUMERIC,
"DP" NUMERIC,
"TP" NUMERIC,
"PB" NUMERIC,
"SB" NUMERIC,
"CS" NUMERIC,
PRIMARY KEY("playerID","yearID","round","POS"),
foreign key("playerID") references "people"("playerID")
);
INSERT INTO "pk_fieldingpost" SELECT DISTINCT * FROM "fieldingpost";
DROP TABLE "fieldingpost";
ALTER TABLE "pk_fieldingpost" RENAME TO "fieldingpost";
COMMIT;

View File

@ -1,40 +0,0 @@
BEGIN;
CREATE TABLE IF NOT EXISTS "pk_pitchingpost" (
"playerID" TEXT,
"yearID" NUMERIC,
"round" NUMERIC,
"teamID" TEXT,
"lgID" TEXT,
"W" NUMERIC,
"L" NUMERIC,
"G" NUMERIC,
"GS" NUMERIC,
"CG" NUMERIC,
"SHO" NUMERIC,
"SV" NUMERIC,
"IPouts" NUMERIC,
"H" NUMERIC,
"ER" NUMERIC,
"HR" NUMERIC,
"BB" NUMERIC,
"SO" NUMERIC,
"BAOpp" NUMERIC,
"ERA" NUMERIC,
"IBB" NUMERIC,
"WP" NUMERIC,
"HBP" NUMERIC,
"BK" NUMERIC,
"BFP" NUMERIC,
"GF" NUMERIC,
"R" NUMERIC,
"SH" NUMERIC,
"SF" NUMERIC,
"GIDP" NUMERIC,
PRIMARY KEY("playerID","yearID","round"),
foreign key("playerID") references "people"("playerID")
);
INSERT INTO "pk_pitchingpost" SELECT DISTINCT * FROM "pitchingpost";
DROP TABLE "pitchingpost";
ALTER TABLE "pk_pitchingpost" RENAME TO "pitchingpost";
COMMIT;

View File

@ -388,4 +388,102 @@ CREATE TABLE IF NOT EXISTS "awardsmanagers" (
); );
insert into awardsmanagers select distinct * from "transformed"."awardsmanagers"; insert into awardsmanagers select distinct * from "transformed"."awardsmanagers";
CREATE TABLE IF NOT EXISTS "battingpost" (
"year" NUMERIC,
"round" NUMERIC,
"player" TEXT,
"G" NUMERIC,
"AB" NUMERIC,
"R" NUMERIC,
"H" NUMERIC,
"2B" NUMERIC,
"3B" NUMERIC,
"HR" NUMERIC,
"RBI" NUMERIC,
"SB" NUMERIC,
"CS" NUMERIC,
"BB" NUMERIC,
"SO" NUMERIC,
"IBB" NUMERIC,
"HBP" NUMERIC,
"SH" NUMERIC,
"SF" NUMERIC,
"GIDP" NUMERIC,
PRIMARY KEY("year","player","round"),
foreign key("player") references "people"("ID"),
foreign key("year") references "seasons"("year")
);
insert into battingpost select distinct * from "transformed"."battingpost";
CREATE TABLE IF NOT EXISTS "fieldingpost" (
"player" TEXT,
"year" NUMERIC,
"round" NUMERIC,
"POS" TEXT,
"G" NUMERIC,
"GS" NUMERIC,
"InnOuts" NUMERIC,
"PO" NUMERIC,
"A" NUMERIC,
"E" NUMERIC,
"DP" NUMERIC,
"TP" NUMERIC,
"PB" NUMERIC,
"SB" NUMERIC,
"CS" NUMERIC,
PRIMARY KEY("player","year","round","POS"),
foreign key("player") references "people"("ID"),
foreign key("year") references "seasons"("year")
);
insert into fieldingpost select distinct * from "transformed"."fieldingpost";
CREATE TABLE IF NOT EXISTS "pitchingpost" (
"player" TEXT,
"year" NUMERIC,
"round" NUMERIC,
"W" NUMERIC,
"L" NUMERIC,
"G" NUMERIC,
"GS" NUMERIC,
"CG" NUMERIC,
"SHO" NUMERIC,
"SV" NUMERIC,
"IPouts" NUMERIC,
"H" NUMERIC,
"ER" NUMERIC,
"HR" NUMERIC,
"BB" NUMERIC,
"SO" NUMERIC,
"BAOpp" NUMERIC,
"ERA" NUMERIC,
"IBB" NUMERIC,
"WP" NUMERIC,
"HBP" NUMERIC,
"BK" NUMERIC,
"BFP" NUMERIC,
"GF" NUMERIC,
"R" NUMERIC,
"SH" NUMERIC,
"SF" NUMERIC,
"GIDP" NUMERIC,
PRIMARY KEY("player","year","round"),
foreign key("player") references "people"("ID"),
foreign key("year") references "seasons"("year")
);
insert into pitchingpost select distinct * from "transformed"."pitchingpost";
create table if not exists appearancespost (
"year" numeric,
"player" text,
"team" text,
primary key("year","player"),
foreign key("player") references "people"("ID"),
foreign key("year","team") references "teamseasons"("year","team")
);
insert into appearancespost select distinct * from "transformed"."appearancespost";
COMMIT; COMMIT;

4
sql/pitchingpost.sql Normal file
View File

@ -0,0 +1,4 @@
begin;
alter table pitchingpost drop column "lgID";
alter table pitchingpost drop column "teamID";
commit;