lahmanlite/sql/keys/homegames.sql

20 lines
482 B
PL/PgSQL

BEGIN;
CREATE TABLE IF NOT EXISTS "pk_homegames" (
"year.key" NUMERIC,
"league.key" TEXT,
"team.key" TEXT,
"park.key" TEXT,
"span.first" TEXT,
"span.last" TEXT,
"games" NUMERIC,
"openings" NUMERIC,
"attendance" NUMERIC,
PRIMARY KEY("year.key","team.key","park.key"),
foreign key("park.key") references "parks"("park.key")
);
INSERT INTO "pk_homegames" SELECT DISTINCT * FROM "homegames";
DROP TABLE "homegames";
ALTER TABLE "pk_homegames" RENAME TO "homegames";
COMMIT;