- -- re-index points that have moved in / out of the polygon, could be done as a single query but postgres gets the index usage wrong
- update placex set indexed_status = 2 where indexed_status = 0
- AND ST_Intersects(NEW.geometry, placex.geometry)
- AND NOT ST_Intersects(existinggeometry, placex.geometry)
- AND rank_search > existingplacex.rank_search AND (rank_search < 28 or name is not null);
+ -- Process it as a new insertion
+ INSERT INTO placex (osm_type, osm_id, class, type, name,
+ admin_level, address, extratags, geometry)
+ VALUES (NEW.osm_type, NEW.osm_id, NEW.class, NEW.type, NEW.name,
+ NEW.admin_level, NEW.address, NEW.extratags, NEW.geometry);
+
+ {% if debug %}RAISE WARNING 'insert done % % % % %',NEW.osm_type,NEW.osm_id,NEW.class,NEW.type,NEW.name;{% endif %}
+
+ IF existing.osm_type is not NULL THEN
+ -- If there is already an entry in place, just update that, if necessary.
+ IF coalesce(existing.name, ''::hstore) != coalesce(NEW.name, ''::hstore)
+ or coalesce(existing.address, ''::hstore) != coalesce(NEW.address, ''::hstore)
+ or coalesce(existing.extratags, ''::hstore) != coalesce(NEW.extratags, ''::hstore)
+ or coalesce(existing.admin_level, 15) != coalesce(NEW.admin_level, 15)
+ or existing.geometry::text != NEW.geometry::text
+ THEN
+ UPDATE place
+ SET name = NEW.name,
+ address = NEW.address,
+ extratags = NEW.extratags,
+ admin_level = NEW.admin_level,
+ geometry = NEW.geometry
+ WHERE osm_type = NEW.osm_type and osm_id = NEW.osm_id
+ and class = NEW.class and type = NEW.type;
+ END IF;