Remove postcodes also from word table when they no longer exist

Also adds tests for postcode updates.

Fixes #1273.
This commit is contained in:
Sarah Hoffmann
2019-01-04 23:11:47 +01:00
parent 181e238b55
commit cc17aa8d6b
4 changed files with 117 additions and 0 deletions

View File

@@ -48,5 +48,11 @@ INSERT INTO location_postcode
SELECT nextval('seq_place'), 1, country_code, pc, centroid
FROM tmp_new_postcode_locations new;
-- Remove unused word entries
DELETE FROM word
WHERE class = 'place' AND type = 'postcode'
AND NOT EXISTS (SELECT 0 FROM location_postcode p
WHERE p.postcode = word.word);
-- Finally index the newly inserted postcodes
UPDATE location_postcode SET indexed_status = 0 WHERE indexed_status > 0;