lahmanlite/sql/pitching.sql

48 lines
1.0 KiB
PL/PgSQL

pragma foreign_keys = 0;
pragma ignore_check_constraints = 1;
begin;
attach database 'baseball-raw.db' as 'raw';
create temp table pitching as
select * from "raw".pitching;
alter table pitching drop column "lgID";
alter table pitching drop column "teamID";
CREATE TABLE IF NOT EXISTS main."pitching" (
"player" TEXT,
"year" NUMERIC,
"stint" NUMERIC,
"W" NUMERIC,
"L" NUMERIC,
"G" NUMERIC check (W + L + SV <= G),
"GS" NUMERIC check (GS <= G),
"CG" NUMERIC check (CG <= GS),
"SHO" NUMERIC check (SHO <= CG),
"SV" NUMERIC,
"IPouts" NUMERIC,
"H" NUMERIC,
"ER" NUMERIC check (ER <= R),
"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","stint"),
foreign key("year","player","stint") references "playerstints"("year","player","stint")
);
insert into main.pitching select distinct * from temp."pitching";
commit;