2024-02-01 04:43:23 +00:00
|
|
|
pragma foreign_keys = 0;
|
|
|
|
|
2024-01-28 06:09:06 +00:00
|
|
|
begin;
|
2024-01-31 06:09:39 +00:00
|
|
|
attach database 'baseball-raw.db' as 'raw';
|
|
|
|
|
|
|
|
create temp table pitchingpost as
|
|
|
|
select * from "raw".pitchingpost;
|
|
|
|
|
2024-01-28 06:09:06 +00:00
|
|
|
alter table pitchingpost drop column "lgID";
|
|
|
|
alter table pitchingpost drop column "teamID";
|
2024-01-31 06:09:39 +00:00
|
|
|
|
2024-02-02 03:45:26 +00:00
|
|
|
update pitchingpost
|
|
|
|
set
|
|
|
|
W = nullif(W, ''),
|
|
|
|
L = nullif(L, ''),
|
|
|
|
G = nullif(G, ''),
|
|
|
|
GS = nullif(GS, ''),
|
|
|
|
CG = nullif(CG, ''),
|
|
|
|
SHO = nullif(SHO, ''),
|
|
|
|
SV = nullif(SV, ''),
|
|
|
|
IPouts = nullif(IPouts, ''),
|
|
|
|
H = nullif(H, ''),
|
|
|
|
ER = nullif(ER, ''),
|
|
|
|
HR = nullif(HR, ''),
|
|
|
|
BB = nullif(BB, ''),
|
|
|
|
SO = nullif(SO, ''),
|
2024-02-04 22:20:07 +00:00
|
|
|
BAOpp = nullif(BAOpp, ''),
|
2024-02-02 03:45:26 +00:00
|
|
|
IBB = nullif(IBB, ''),
|
2024-02-04 22:20:07 +00:00
|
|
|
WP = nullif(WP, ''),
|
2024-02-02 03:45:26 +00:00
|
|
|
HBP = nullif(HBP, ''),
|
2024-02-04 22:20:07 +00:00
|
|
|
BK = nullif(BK, ''),
|
2024-02-02 03:45:26 +00:00
|
|
|
BFP = nullif(BFP, ''),
|
|
|
|
GF = nullif(GF, ''),
|
|
|
|
R = nullif(R, ''),
|
|
|
|
SH = nullif(SH, ''),
|
|
|
|
SF = nullif(SF, ''),
|
|
|
|
GIDP = nullif(GIDP, '');
|
|
|
|
|
2024-01-31 06:09:39 +00:00
|
|
|
CREATE TABLE IF NOT EXISTS main."pitchingpost" (
|
|
|
|
"player" TEXT,
|
|
|
|
"year" NUMERIC,
|
|
|
|
"round" NUMERIC,
|
2024-02-02 03:45:26 +00:00
|
|
|
"W" NUMERIC check (W <= G),
|
|
|
|
"L" NUMERIC check (L <= G),
|
|
|
|
"G" NUMERIC check (W + L + SV <= G),
|
|
|
|
"GS" NUMERIC check (GS <= G),
|
|
|
|
"CG" NUMERIC check (CG <= GS),
|
|
|
|
"SHO" NUMERIC check (SHO <= G),
|
|
|
|
"SV" NUMERIC check (SV <= G),
|
2024-01-31 06:09:39 +00:00
|
|
|
"IPouts" NUMERIC,
|
|
|
|
"H" NUMERIC,
|
2024-02-02 03:45:26 +00:00
|
|
|
"ER" NUMERIC check (ER <= R),
|
|
|
|
"HR" NUMERIC check (HR <= H),
|
2024-01-31 06:09:39 +00:00
|
|
|
"BB" NUMERIC,
|
2024-02-02 03:45:26 +00:00
|
|
|
"SO" NUMERIC check (SO <= IPouts),
|
2024-01-31 06:09:39 +00:00
|
|
|
"BAOpp" NUMERIC,
|
|
|
|
"ERA" NUMERIC,
|
|
|
|
"IBB" NUMERIC,
|
|
|
|
"WP" NUMERIC,
|
|
|
|
"HBP" NUMERIC,
|
|
|
|
"BK" NUMERIC,
|
|
|
|
"BFP" NUMERIC,
|
2024-02-02 03:45:26 +00:00
|
|
|
"GF" NUMERIC check (GF <= G),
|
2024-01-31 06:09:39 +00:00
|
|
|
"R" NUMERIC,
|
|
|
|
"SH" NUMERIC,
|
|
|
|
"SF" NUMERIC,
|
2024-02-02 03:45:26 +00:00
|
|
|
"GIDP" NUMERIC check (2 * GIDP <= IPouts),
|
2024-01-31 06:09:39 +00:00
|
|
|
PRIMARY KEY("player","year","round"),
|
|
|
|
foreign key("player","year") references "appearancespost"("player","year"),
|
|
|
|
foreign key("year","round") references "seriespost"("year","round")
|
|
|
|
);
|
|
|
|
|
|
|
|
insert into main.pitchingpost select distinct * from temp."pitchingpost";
|
2024-01-28 06:09:06 +00:00
|
|
|
commit;
|