]> git.openstreetmap.org Git - nominatim.git/blob - lib-sql/functions/associated_street_triggers.sql
prepare release 5.3.2.post2
[nominatim.git] / lib-sql / functions / associated_street_triggers.sql
1 -- SPDX-License-Identifier: GPL-2.0-only
2 --
3 -- This file is part of Nominatim. (https://nominatim.org)
4 --
5 -- Copyright (C) 2026 by the Nominatim developer community.
6 -- For a full list of authors see the git log.
7
8 -- Trigger functions for associated street relations.
9
10
11 -- Invalidates house members of associatedStreet relations
12 -- whenever the place_associated_street table is modified.
13 -- osm2pgsql flex handles updates as DELETE-all + re-INSERT, so each
14 -- row-level trigger call covers exactly one member.
15 CREATE OR REPLACE FUNCTION invalidate_associated_street_members()
16   RETURNS TRIGGER
17   AS $$
18 DECLARE
19   object RECORD;
20 BEGIN
21   IF TG_OP = 'DELETE' THEN
22     object := OLD;
23   ELSE
24     object := NEW;
25   END IF;
26
27   IF object.member_role = 'house' THEN
28     {% for otype in ('N', 'W', 'R') %}
29     IF object.member_type = '{{ otype }}' THEN
30       UPDATE placex SET indexed_status = 2
31        WHERE osm_type = '{{ otype }}'
32          AND osm_id = object.member_id
33          AND indexed_status = 0;
34     END IF;
35     {% endfor %}
36   END IF;
37
38   RETURN object;
39 END;
40 $$
41 LANGUAGE plpgsql;