Statcast: role belongs in the key (two-way players)
Found by inducing the real job on the server, not by review: the first chunk wrote, the second failed with 'ON CONFLICT DO UPDATE command cannot affect row a second time'. A player can legitimately appear in BOTH the batter and the pitcher feeds — two-way players, position players who pitch, pitchers who bat — so (sport, season, source_id) collapsed two real profiles into one key and a single batch hit the same row twice. Ohtani has a real batter profile and a real pitcher profile. Merging them would invent one player out of two genuinely different sets of measurements, so role goes in the primary key rather than one profile winning. Migration 031 applied; conflict target updated; a two-way case is now a test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VCNgGSt5qvcLxaeQqa7Zpj
This commit is contained in:
@@ -60,7 +60,9 @@ create table if not exists statcast_aggregates (
|
||||
updated_at timestamptz not null default now(),
|
||||
source text not null default 'baseball_savant',
|
||||
|
||||
primary key (sport, season, source_id)
|
||||
-- ROLE is in the key: two-way players have a real batter profile AND a
|
||||
-- real pitcher profile (see migration 031).
|
||||
primary key (sport, season, source_id, role)
|
||||
);
|
||||
|
||||
create index if not exists statcast_agg_player_key_idx on statcast_aggregates (sport, season, player_key);
|
||||
|
||||
Reference in New Issue
Block a user