35 lines
817 B
PL/PgSQL
35 lines
817 B
PL/PgSQL
pragma foreign_keys = 0;
|
|
|
|
begin;
|
|
attach database 'baseball-raw.db' as 'raw';
|
|
create temp table if not exists "halloffamereqs" (
|
|
"yearID" numeric,
|
|
"votedBy" text,
|
|
"ballots" numeric,
|
|
"needed" numeric,
|
|
"needed_note" text
|
|
);
|
|
|
|
insert into halloffamereqs
|
|
select distinct yearid, votedby, ballots, needed, "needed_note"
|
|
from "raw".halloffame;
|
|
|
|
update halloffamereqs
|
|
set
|
|
ballots = nullif(ballots,''),
|
|
needed = nullif(needed,''),
|
|
"needed_note" = nullif("needed_note",'');
|
|
|
|
create table if not exists main."halloffamereqs" (
|
|
"year" numeric,
|
|
"votedBy" text,
|
|
"ballots" numeric,
|
|
"needed" numeric check ("needed" <= "ballots"),
|
|
"needed_note" text,
|
|
primary key("year","votedBy"),
|
|
foreign key("year") references "seasons"("year")
|
|
);
|
|
|
|
insert into main.halloffamereqs select distinct * from temp.halloffamereqs;
|
|
commit;
|