text: insert into event
  select
    game_id || to_char(event_id::integer, 'FM000') as event_uid,
    game_id,
    date(substring(game_id from 4 for 8)) as game_date,
    substring(game_id from 4 for 4)::integer as game_year,
    substring(game_id from 8 for 2)::integer as game_month,
    substring(game_id from 10 for 2)::integer as game_day_of_month,
    substring(game_id from 12 for 1)::integer as game_number,
    substring(game_id from 1 for 3) as home_team_id,
    away_team_id,
    inn_ct::integer,
    bat_home_id::boolean,
    game_id || to_char(inn_ct::integer, 'FM00') || bat_home_id as half_inning_id,
    outs_ct::integer,
    balls_ct::integer,
    strikes_ct::integer,
    nullif(pitch_seq_tx, ''),
    away_score_ct::integer,
    home_score_ct::integer,
    away_score_ct::integer + home_score_ct::integer as runs,
    bat_id,
    nullif(bat_hand_cd, '?')::hand_cd_type,
    resp_bat_id,
    nullif(resp_bat_hand_cd, '?')::hand_cd_type,
    pit_id,
    pit_hand_cd::hand_cd_type,
    resp_pit_id,
    resp_pit_hand_cd::hand_cd_type,
    pos2_fld_id,
    pos3_fld_id,
    pos4_fld_id,
    pos5_fld_id,
    pos6_fld_id,
    pos7_fld_id,
    pos8_fld_id,
    pos9_fld_id,
    nullif(base1_run_id, ''),
    nullif(base2_run_id, ''),
    nullif(base3_run_id, ''),
    event_tx,
    leadoff_fl::boolean,
    ph_fl::boolean,
    bat_fld_cd::integer,
    bat_lineup_id::integer,
    event_cd::integer,
    bat_event_fl::boolean,
    ab_fl::boolean,
    h_fl::integer,
    sh_fl::boolean,
    sf_fl::boolean,
    event_outs_ct::integer,
    dp_fl::boolean,
    tp_fl::boolean,
    rbi_ct::integer,
    wp_fl::boolean,
    pb_fl::boolean,
    fld_cd::integer,
    nullif(battedball_cd, '')::battedball_cd_type,
    bunt_fl::boolean,
    foul_fl::boolean,
    nullif(battedball_loc_tx, ''),
    err_ct::integer,
    err1_fld_cd::integer,
    err1_cd::err_cd_type,
    err2_fld_cd::integer,
    err2_cd::err_cd_type,
    err3_fld_cd::integer,
    err3_cd::err_cd_type,
    bat_dest_id::integer,
    run1_dest_id::integer,
    run2_dest_id::integer,
    run3_dest_id::integer,
    (bat_dest_id::integer > 3)::integer + (run1_dest_id::integer > 3)::integer + (run2_dest_id::integer > 3)::integer + (run3_dest_id::integer > 3)::integer as runs_scored,
    nullif(bat_play_tx, ''),
    nullif(run1_play_tx, ''),
    nullif(run2_play_tx, ''),
    nullif(run3_play_tx, ''),
    run1_sb_fl::boolean,
    run2_sb_fl::boolean,
    run3_sb_fl::boolean,
    run1_cs_fl::boolean,
    run2_cs_fl::boolean,
    run3_cs_fl::boolean,
    run1_pk_fl::boolean,
    run2_pk_fl::boolean,
    run3_pk_fl::boolean,
    nullif(run1_resp_pit_id, ''),
    nullif(run2_resp_pit_id, ''),
    nullif(run3_resp_pit_id, ''),
    game_new_fl::boolean,
    game_end_fl::boolean,
    pr_run1_fl::boolean,
    pr_run2_fl::boolean,
    pr_run3_fl::boolean,
    nullif(removed_for_pr_run1_id, ''),
    nullif(removed_for_pr_run2_id, ''),
    nullif(removed_for_pr_run3_id, ''),
    nullif(removed_for_ph_bat_id, ''),
    nullif(removed_for_ph_bat_fld_cd, '0')::integer,
    po1_fld_cd::integer,
    po2_fld_cd::integer,
    po3_fld_cd::integer,
    ass1_fld_cd::integer,
    ass2_fld_cd::integer,
    ass3_fld_cd::integer,
    ass4_fld_cd::integer,
    ass5_fld_cd::integer,
    event_id::integer
  from
    event_ingest
  ;
  