move postseasons tables
This commit is contained in:
19
sql/appearancespost.sql
Normal file
19
sql/appearancespost.sql
Normal 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
4
sql/battingpost.sql
Normal 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
4
sql/fieldingpost.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
begin;
|
||||
alter table fieldingpost drop column "lgID";
|
||||
alter table fieldingpost drop column "teamID";
|
||||
commit;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
98
sql/load.sql
98
sql/load.sql
@@ -388,4 +388,102 @@ CREATE TABLE IF NOT EXISTS "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;
|
||||
|
||||
4
sql/pitchingpost.sql
Normal file
4
sql/pitchingpost.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
begin;
|
||||
alter table pitchingpost drop column "lgID";
|
||||
alter table pitchingpost drop column "teamID";
|
||||
commit;
|
||||
Reference in New Issue
Block a user