Skip to content

Commit

Permalink
Update replication and added sql
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitijrajsharma committed Nov 19, 2023
1 parent 113eb2e commit 9e5855d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions backend/replication
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,8 @@ def update_country(conn, timestamp, table_name, c_id=None, boundary=None):
with conn.cursor() as cur:
update_query = f"""WITH t1 AS (SELECT osm_id, ST_Centroid(geom) AS geom FROM {table_name} WHERE "timestamp" >= '{timestamp}'), t2 AS (SELECT t1.osm_id,
CASE
WHEN COUNT(cg.cid) = 0 THEN ARRAY[0]::integer[]
ELSE array_agg(COALESCE(cg.cid, 0))
WHEN COUNT(cg.cid) = 0 THEN ARRAY[1000]::integer[]
ELSE array_agg(COALESCE(cg.cid, 1000))
END AS aa_fids
FROM t1 LEFT JOIN countries cg ON ST_Intersects(t1.geom, cg.geometry) GROUP BY t1.osm_id) UPDATE {table_name} uw SET country = t2.aa_fids FROM t2 WHERE t2.osm_id = uw.osm_id;"""

Expand Down
3 changes: 3 additions & 0 deletions backend/sql/update_countries.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
WITH t1 AS (SELECT osm_id, ST_Centroid(geom) AS geom FROM nodes wl WHERE country <@ Array[0]),
t2 AS (SELECT t1.osm_id, CASE WHEN COUNT(cg.cid) = 0 THEN ARRAY[1000]::INTEGER[] ELSE ARRAY_AGG(COALESCE(cg.cid, 1000)) END AS aa_fids FROM t1 LEFT JOIN countries cg ON ST_Intersects(t1.geom, cg.geometry) GROUP BY t1.osm_id)
UPDATE nodes uw SET country = t2.aa_fids FROM t2 WHERE t2.osm_id = uw.osm_id;

0 comments on commit 9e5855d

Please sign in to comment.