lahmanlite/sql/awardsmanagers.sql

24 lines
615 B
PL/PgSQL

pragma foreign_keys = 0;
begin;
attach database 'baseball-raw.db' as 'raw';
create temp table "awardsmanagers" as
select * from "raw".awardsmanagers;
alter table temp.awardsmanagers drop column "tie";
CREATE TABLE IF NOT EXISTS main."awardsmanagers" (
"manager" TEXT,
"award" TEXT,
"year" NUMERIC,
"league" TEXT,
"notes" TEXT,
PRIMARY KEY("manager","award","year","league"),
foreign key("manager") references "people"("ID"),
foreign key("award","year","league") references "yearlyawards"("award","year","league")
);
insert into main.awardsmanagers select distinct * from temp."awardsmanagers";
commit;