The statement ended with SELECT COUNT(*) FROM inserted, but the inserted
CTE has no RETURNING clause — PostgreSQL rejects referencing such a CTE
(SQLSTATE 0A000), so every UpdateEpisodeLink call has errored since #283.
The sole caller logs a warning and continues, so the metadata-side
single-file episode relink silently did nothing: episode_id stayed stale,
episode_libraries rows were not inserted, latest_episode_added_at was not
bumped. Bulk linking uses the correct pattern and masked the breakage.
The INSERT is now the top-level statement; the count was unused.
Verified against a migrated PostgreSQL scratch database:
TestEpisodeLinkMaintainsLatestEpisodeAdded fails on main with the exact
error and passes with this change.
Fixes#320
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>