30 lines
580 B
PL/PgSQL
30 lines
580 B
PL/PgSQL
pragma foreign_keys = 0;
|
|
|
|
begin;
|
|
attach database 'baseball-raw.db' as 'raw';
|
|
create temp table if not exists teams (
|
|
"ID" text,
|
|
"franchise" text
|
|
);
|
|
|
|
insert into teams
|
|
select distinct teamid, franchid from "raw"."teams";
|
|
|
|
update teams
|
|
set ID = 'WS9'
|
|
where ID = 'WAS' and franchise = 'WAS';
|
|
|
|
update teams
|
|
set ID = 'PHP'
|
|
where ID = 'PH4' and franchise = 'PHQ';
|
|
|
|
create table if not exists main.teams (
|
|
"ID" text,
|
|
"franchise" text,
|
|
primary key("ID"),
|
|
foreign key("franchise") references "franchises"("ID")
|
|
);
|
|
|
|
insert into main.teams select distinct * from temp."teams";
|
|
commit;
|