lahmanlite/sql/fieldingpost.sql

35 lines
819 B
PL/PgSQL

pragma foreign_keys = 0;
begin;
attach database 'baseball-raw.db' as 'raw';
create temp table fieldingpost as
select * from "raw".fieldingpost;
alter table fieldingpost drop column "lgID";
alter table fieldingpost drop column "teamID";
CREATE TABLE IF NOT EXISTS main."fieldingpost" (
"player" TEXT,
"year" NUMERIC,
"round" NUMERIC,
"POS" TEXT,
"G" NUMERIC,
"GS" NUMERIC,
"InnOuts" NUMERIC,
"PO" NUMERIC check (PO <= InnOuts),
"A" NUMERIC,
"E" NUMERIC,
"DP" NUMERIC,
"TP" NUMERIC,
"PB" NUMERIC,
"SB" NUMERIC,
"CS" NUMERIC,
PRIMARY KEY("player","year","round","POS"),
foreign key("player","year") references "appearancespost"("player","year"),
foreign key("year","round") references "seriespost"("year","round")
);
insert into main.fieldingpost select distinct * from temp."fieldingpost";
commit;