CREATE TABLE filenames (
  recdate timestamp NOT NULL,
  season smallint NOT NULL,
  partno smallint,
  station text NOT NULL,
  eptitle text NOT NULL
);
CREATE TABLE episodes (
  epnum text NOT NULL,
  season smallint NOT NULL,
  title text NOT NULL,
  partno smallint
);

CREATE TABLE episodes_chld () INHERITS (episodes);

\set tsearch_sql `pg_config --sharedir`/contrib/tsearch2.sql
\i :tsearch_sql
EXPLAIN SELECT epnum, filenames.* FROM filenames LEFT JOIN episodes ON (
  filenames.season = episodes.season AND
  strip(to_tsvector(filenames.eptitle)) = strip(to_tsvector(episodes.title)) AND
  filenames.partno IS NOT DISTINCT FROM episodes.partno)
WHERE epnum IS NULL;

-- vim: set ft=psql ts=2 sw=2 expandtab :
