postgresql7.1 SELECT distinct crftd.path, crftd.storage_area_key FROM cr_files_to_delete crftd WHERE not exists (SELECT 1 FROM cr_revisions r WHERE substring(r.content for 100) = substring(crftd.path for 100)) SELECT count(*) FROM cr_revisions WHERE substring(content, 1, 100) = substring(:name, 1, 100);