lahmanlite/sql/keys/appearances.sql

32 lines
676 B
PL/PgSQL

begin;
CREATE TABLE IF NOT EXISTS "pk_appearances" (
"yearID" NUMERIC,
"teamID" TEXT,
"lgID" TEXT,
"playerID" TEXT,
"G_all" NUMERIC,
"GS" NUMERIC,
"G_batting" NUMERIC,
"G_defense" NUMERIC,
"G_p" NUMERIC,
"G_c" NUMERIC,
"G_1b" NUMERIC,
"G_2b" NUMERIC,
"G_3b" NUMERIC,
"G_ss" NUMERIC,
"G_lf" NUMERIC,
"G_cf" NUMERIC,
"G_rf" NUMERIC,
"G_of" NUMERIC,
"G_dh" NUMERIC,
"G_ph" NUMERIC,
"G_pr" NUMERIC,
PRIMARY KEY("yearID","teamID","playerID"),
foreign key("playerID") references "people"("playerID")
);
INSERT INTO "pk_appearances" SELECT DISTINCT * FROM "appearances";
DROP TABLE "appearances";
ALTER TABLE "pk_appearances" RENAME TO "appearances";
commit;