pragma foreign_keys = 0;

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,
	"GS"	NUMERIC,
	"CG"	NUMERIC,
	"SHO"	NUMERIC,
	"SV"	NUMERIC,
	"IPouts"	NUMERIC,
	"H"	NUMERIC,
	"ER"	NUMERIC,
	"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;
