update foreign keys
This commit is contained in:
parent
4355180c43
commit
eb489be084
25
sql/load.sql
25
sql/load.sql
|
@ -164,8 +164,7 @@ CREATE TABLE IF NOT EXISTS "salaries" (
|
||||||
"salary" NUMERIC,
|
"salary" NUMERIC,
|
||||||
PRIMARY KEY("year","player","team"),
|
PRIMARY KEY("year","player","team"),
|
||||||
foreign key("player") references "people"("ID"),
|
foreign key("player") references "people"("ID"),
|
||||||
foreign key("team") references "teams"("ID"),
|
foreign key("year","team") references "teamseasons"("year","team")
|
||||||
foreign key("year") references "seasons"("year")
|
|
||||||
);
|
);
|
||||||
|
|
||||||
insert into salaries select distinct * from "transformed"."salaries";
|
insert into salaries select distinct * from "transformed"."salaries";
|
||||||
|
@ -194,8 +193,7 @@ CREATE TABLE IF NOT EXISTS "batting" (
|
||||||
"GIDP" NUMERIC,
|
"GIDP" NUMERIC,
|
||||||
PRIMARY KEY("player","year","stint","team"),
|
PRIMARY KEY("player","year","stint","team"),
|
||||||
foreign key("player") references "people"("ID"),
|
foreign key("player") references "people"("ID"),
|
||||||
foreign key("team") references "teams"("ID"),
|
foreign key("year","team") references "teamseasons"("year","team")
|
||||||
foreign key("year") references "seasons"("year")
|
|
||||||
);
|
);
|
||||||
|
|
||||||
insert into batting select distinct * from "transformed"."batting";
|
insert into batting select distinct * from "transformed"."batting";
|
||||||
|
@ -220,8 +218,7 @@ CREATE TABLE IF NOT EXISTS "fielding" (
|
||||||
"ZR" NUMERIC,
|
"ZR" NUMERIC,
|
||||||
PRIMARY KEY("player","year","stint","team","POS"),
|
PRIMARY KEY("player","year","stint","team","POS"),
|
||||||
foreign key("player") references "people"("ID"),
|
foreign key("player") references "people"("ID"),
|
||||||
foreign key("team") references "teams"("ID"),
|
foreign key("year","team") references "teamseasons"("year","team")
|
||||||
foreign key("year") references "seasons"("year")
|
|
||||||
);
|
);
|
||||||
|
|
||||||
insert into fielding select distinct * from "transformed"."fielding";
|
insert into fielding select distinct * from "transformed"."fielding";
|
||||||
|
@ -258,8 +255,7 @@ CREATE TABLE IF NOT EXISTS "pitching" (
|
||||||
"GIDP" NUMERIC,
|
"GIDP" NUMERIC,
|
||||||
PRIMARY KEY("player","year","stint","team"),
|
PRIMARY KEY("player","year","stint","team"),
|
||||||
foreign key("player") references "people"("ID"),
|
foreign key("player") references "people"("ID"),
|
||||||
foreign key("team") references "teams"("ID"),
|
foreign key("year","team") references "teamseasons"("year","team")
|
||||||
foreign key("year") references "seasons"("year")
|
|
||||||
);
|
);
|
||||||
|
|
||||||
insert into pitching select distinct * from "transformed"."pitching";
|
insert into pitching select distinct * from "transformed"."pitching";
|
||||||
|
@ -287,8 +283,7 @@ CREATE TABLE IF NOT EXISTS "appearances" (
|
||||||
"G_pr" NUMERIC,
|
"G_pr" NUMERIC,
|
||||||
PRIMARY KEY("year","team","player"),
|
PRIMARY KEY("year","team","player"),
|
||||||
foreign key("player") references "people"("ID"),
|
foreign key("player") references "people"("ID"),
|
||||||
foreign key("team") references "teams"("ID"),
|
foreign key("year","team") references "teamseasons"("year","team")
|
||||||
foreign key("year") references "seasons"("year")
|
|
||||||
);
|
);
|
||||||
|
|
||||||
insert into appearances select distinct * from "transformed"."appearances";
|
insert into appearances select distinct * from "transformed"."appearances";
|
||||||
|
@ -304,8 +299,7 @@ CREATE TABLE IF NOT EXISTS "homegames" (
|
||||||
"attendance" NUMERIC,
|
"attendance" NUMERIC,
|
||||||
PRIMARY KEY("year","team","park"),
|
PRIMARY KEY("year","team","park"),
|
||||||
foreign key("park") references "parks"("ID"),
|
foreign key("park") references "parks"("ID"),
|
||||||
foreign key("team") references "teams"("ID"),
|
foreign key("year","team") references "teamseasons"("year","team")
|
||||||
foreign key("year") references "seasons"("year")
|
|
||||||
);
|
);
|
||||||
|
|
||||||
insert into homegames select distinct * from "transformed"."homegames";
|
insert into homegames select distinct * from "transformed"."homegames";
|
||||||
|
@ -319,7 +313,9 @@ CREATE TABLE IF NOT EXISTS "seriespost" (
|
||||||
"losses" NUMERIC,
|
"losses" NUMERIC,
|
||||||
"ties" NUMERIC,
|
"ties" NUMERIC,
|
||||||
PRIMARY KEY("year","round"),
|
PRIMARY KEY("year","round"),
|
||||||
foreign key("year") references "seasons"("year")
|
foreign key("year") references "seasons"("year"),
|
||||||
|
foreign key("winner") references "teams"("ID"),
|
||||||
|
foreign key("loser") references "teams"("ID")
|
||||||
);
|
);
|
||||||
|
|
||||||
insert into seriespost select distinct * from "transformed"."seriespost";
|
insert into seriespost select distinct * from "transformed"."seriespost";
|
||||||
|
@ -344,8 +340,7 @@ CREATE TABLE IF NOT EXISTS "fieldingofsplit" (
|
||||||
"ZR" NUMERIC,
|
"ZR" NUMERIC,
|
||||||
PRIMARY KEY("player","year","stint","team","POS"),
|
PRIMARY KEY("player","year","stint","team","POS"),
|
||||||
foreign key("player") references "people"("ID"),
|
foreign key("player") references "people"("ID"),
|
||||||
foreign key("team") references "teams"("ID"),
|
foreign key("year","team") references "teamseasons"("year","team")
|
||||||
foreign key("year") references "seasons"("year")
|
|
||||||
);
|
);
|
||||||
|
|
||||||
insert into fieldingofsplit select distinct * from "transformed"."fieldingofsplit";
|
insert into fieldingofsplit select distinct * from "transformed"."fieldingofsplit";
|
||||||
|
|
Loading…
Reference in New Issue