lahmanlite/sql/parks.sql

32 lines
845 B
MySQL
Raw Normal View History

2024-01-26 03:43:23 +00:00
begin;
2024-01-28 00:59:05 +00:00
attach database 'baseball-raw.db' as 'raw';
2024-01-26 03:43:23 +00:00
create table if not exists "parkaliases" (
"parkID" text,
2024-01-28 00:59:05 +00:00
"alias" text
2024-01-26 03:43:23 +00:00
);
2024-01-26 04:53:39 +00:00
-- split aliases by semicolon
with recursive aliases(parkid, alias) as (
2024-01-28 00:59:05 +00:00
select "park.key", "park.alias" from "raw"."parks"
2024-01-26 04:53:39 +00:00
union
select parkid, trim(substr(alias, instr(alias, ";") + 1)) as a
from aliases
where a != ''
) insert into parkaliases
select parkid, case instr(alias, ";")
when 0 then alias
else trim(substr(alias, 1, instr(alias, ";") - 1)) end as a
from aliases
where a != '';
2024-01-26 17:47:18 +00:00
alter table parks drop column "park.alias";
2024-01-28 01:05:31 +00:00
-- insert some missing parks
insert into parks values
('ARL03', 'Globe Life Field', 'Arlington', 'TX', 'US'),
('BUF05', 'Sahlen Field', 'Buffalo', 'NY', 'US'),
('DUN01', 'TD Ballpark', 'Dunedin', 'FL', 'US'),
('DYE01', 'Field of Dreams', 'Dyersville', 'IA', 'US');
2024-01-26 03:43:23 +00:00
commit;