lahmanlite/sql/managers.sql

34 lines
783 B
PL/PgSQL

begin;
attach database 'baseball-raw.db' as 'raw';
create temp table managers as
select * from "raw".managers;
alter table managers drop column "lgID";
alter table managers drop column "rank";
update managers
set teamid = 'WS9'
where teamid = 'WAS' and yearid between 1891 and 1899;
update managers
set teamid = 'PHP'
where teamid = 'PH4' and yearid between 1890 and 1891;
CREATE TABLE IF NOT EXISTS main."managers" (
"ID" TEXT,
"year" NUMERIC,
"team" TEXT,
"inseason" NUMERIC,
"G" NUMERIC,
"W" NUMERIC,
"L" NUMERIC,
"plyrMgr" TEXT,
PRIMARY KEY("ID","year","team","inseason"),
foreign key("ID") references "people"("ID"),
foreign key("year","team") references "teamseasons"("year","team")
);
insert into main.managers select distinct * from temp."managers";
commit;