lahmanlite/sql/batting.sql

41 lines
864 B
PL/PgSQL

begin;
attach database 'baseball-raw.db' as 'raw';
create temp table batting as
select * from "raw".batting;
alter table batting drop column "lgID";
alter table batting drop column "teamID";
-- bbref doesn't say this guy played in 1911
delete from batting
where playerid = 'smithbu01' and yearid = 1911;
CREATE TABLE IF NOT EXISTS main."batting" (
"player" TEXT,
"year" NUMERIC,
"stint" NUMERIC,
"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("player","year","stint"),
foreign key("year","player","stint") references "playerstints"("year","player","stint")
);
insert into main.batting select distinct * from temp."batting";
commit;