2024-02-01 04:43:23 +00:00
|
|
|
pragma foreign_keys = 0;
|
|
|
|
|
2024-01-30 02:34:07 +00:00
|
|
|
begin;
|
2024-01-31 06:09:39 +00:00
|
|
|
attach database 'baseball-raw.db' as 'raw';
|
|
|
|
|
|
|
|
CREATE TEMP TABLE "allstarstartingpos" (
|
|
|
|
"player" NUMERIC,
|
|
|
|
"year" NUMERIC,
|
|
|
|
"gameNum" NUMERIC,
|
|
|
|
"league" NUMERIC,
|
|
|
|
"startingPos" NUMERIC,
|
|
|
|
"gameid" text
|
|
|
|
);
|
|
|
|
|
|
|
|
insert into "allstarstartingpos"
|
|
|
|
select distinct playerid, yearid, gamenum, lgid, startingpos, gameid
|
|
|
|
from "raw".allstarfull;
|
2024-01-30 02:34:07 +00:00
|
|
|
|
|
|
|
-- fix game numbers for 1962 all-star games
|
|
|
|
update allstarstartingpos
|
|
|
|
set gamenum = 1
|
|
|
|
where gameid = 'ALS196207100';
|
|
|
|
|
|
|
|
update allstarstartingpos
|
|
|
|
set gamenum = 2
|
|
|
|
where gameid = 'NLS196207300';
|
|
|
|
|
2024-01-31 02:30:24 +00:00
|
|
|
-- rocky colavito was a reserve, not starter
|
|
|
|
delete from allstarstartingpos
|
2024-01-31 06:09:39 +00:00
|
|
|
where gameid = 'ALS196207100' and player = 'colavro01';
|
2024-01-31 02:30:24 +00:00
|
|
|
|
2024-01-31 06:09:39 +00:00
|
|
|
alter table allstarstartingpos drop column "gameid";
|
2024-01-30 02:34:07 +00:00
|
|
|
|
|
|
|
update allstarstartingpos
|
|
|
|
set startingpos = null
|
|
|
|
where startingpos = '';
|
|
|
|
|
|
|
|
delete from allstarstartingpos
|
|
|
|
where startingpos is null;
|
2024-01-31 06:09:39 +00:00
|
|
|
|
|
|
|
CREATE TABLE "allstarstartingpos" (
|
|
|
|
"player" NUMERIC,
|
|
|
|
"year" NUMERIC,
|
|
|
|
"gameNum" NUMERIC,
|
|
|
|
"league" NUMERIC,
|
2024-02-02 02:48:12 +00:00
|
|
|
"startingPos" NUMERIC check ("startingPos" in (1,2,3,4,5,6,7,8,9,10)),
|
2024-01-31 06:09:39 +00:00
|
|
|
primary key("year","gameNum","league","startingPos"),
|
2024-02-02 01:45:40 +00:00
|
|
|
unique("year","gameNum","league","startingPos"),
|
2024-01-31 06:09:39 +00:00
|
|
|
foreign key("player","year","gameNum") references "allstars"("player","year","gameNum"),
|
|
|
|
foreign key("league") references "leagues"("ID")
|
|
|
|
);
|
|
|
|
|
|
|
|
insert into main.allstarstartingpos select distinct * from temp.allstarstartingpos;
|
2024-01-30 02:34:07 +00:00
|
|
|
commit;
|