2024-02-01 04:43:23 +00:00
|
|
|
pragma foreign_keys = 0;
|
|
|
|
|
2024-01-26 20:03:29 +00:00
|
|
|
begin;
|
2024-01-31 06:09:39 +00:00
|
|
|
attach database 'baseball-raw.db' as 'raw';
|
|
|
|
|
|
|
|
create temp table pitching as
|
|
|
|
select * from "raw".pitching;
|
|
|
|
|
2024-01-26 20:03:29 +00:00
|
|
|
alter table pitching drop column "lgID";
|
2024-01-30 03:43:52 +00:00
|
|
|
alter table pitching drop column "teamID";
|
2024-01-31 06:09:39 +00:00
|
|
|
|
2024-02-02 03:45:26 +00:00
|
|
|
-- it seems like Doc White was improperly credited with a win and save for game
|
|
|
|
-- 2 of 1902-09-02 when he should only have been credited with a save
|
|
|
|
update pitching
|
|
|
|
set W = 15
|
|
|
|
where playerID = 'whitedo01' and yearid = 1902 and stint = 1;
|
|
|
|
|
|
|
|
-- Give his win to Chick Fraser
|
|
|
|
update pitching
|
|
|
|
set W = 13
|
|
|
|
where playerID = 'frasech01' and yearid = 1902 and stint = 1;
|
|
|
|
|
|
|
|
update pitching
|
|
|
|
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, ''),
|
|
|
|
HBP = nullif(HBP, ''),
|
|
|
|
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."pitching" (
|
|
|
|
"player" TEXT,
|
|
|
|
"year" NUMERIC,
|
|
|
|
"stint" 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","stint"),
|
|
|
|
foreign key("year","player","stint") references "playerstints"("year","player","stint")
|
|
|
|
);
|
|
|
|
|
|
|
|
insert into main.pitching select distinct * from temp."pitching";
|
2024-01-26 20:03:29 +00:00
|
|
|
commit;
|