-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add update_fk_main_cover and fk_main_node to symbology functions
Create delta for it also
- Loading branch information
Showing
2 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
delta/delta_1.6.3_functions_update_fk_main_cover_main_wastewater_node.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
|
||
-------------------------------------------------------- | ||
-- UPDATE wastewater structure fk_main_cover | ||
-- Argument: | ||
-- * obj_id of wastewater structure | ||
-- * all True to update all | ||
-- * omit both arguments to update all where fk_main_cover is null | ||
-------------------------------------------------------- | ||
CREATE OR REPLACE FUNCTION qgep_od.wastewater_structure_update_fk_main_cover(_obj_id text default NULL, _all boolean default false) | ||
RETURNS VOID AS | ||
$BODY$ | ||
DECLARE | ||
myrec record; | ||
|
||
BEGIN | ||
UPDATE qgep_od.wastewater_structure ws | ||
SET fk_main_cover = ws_covers.co_obj_id | ||
FROM ( | ||
SELECT ws.obj_id, min(co.obj_id) OVER (PARTITION BY ws.obj_id) AS co_obj_id | ||
FROM qgep_od.wastewater_structure ws | ||
LEFT JOIN qgep_od.structure_part sp ON sp.fk_wastewater_structure = ws.obj_id | ||
LEFT JOIN qgep_od.cover co ON sp.obj_id = co.obj_id | ||
LEFT JOIN qgep_od.channel ch ON ch.obj_id = ws.obj_id | ||
WHERE ch.obj_id IS NULL AND (_all OR ws.obj_id = _obj_id OR ( NOT _all AND _obj_id is NULL AND ws.fk_main_cover IS NULL)) | ||
) ws_covers | ||
WHERE ws.obj_id = ws_covers.obj_id; | ||
END | ||
|
||
$BODY$ | ||
LANGUAGE plpgsql | ||
VOLATILE; | ||
|
||
-------------------------------------------------------- | ||
-- UPDATE wastewater structure fk_main_wastewater_node | ||
-- Argument: | ||
-- * obj_id of wastewater structure | ||
-- * all True to update all | ||
-- * omit both arguments to update all where fk_main_wastewater_node is null | ||
-------------------------------------------------------- | ||
|
||
CREATE OR REPLACE FUNCTION qgep_od.wastewater_structure_update_fk_main_wastewater_node(_obj_id text default NULL, _all boolean default false) | ||
RETURNS VOID AS | ||
$BODY$ | ||
DECLARE | ||
myrec record; | ||
|
||
BEGIN | ||
UPDATE qgep_od.wastewater_structure ws | ||
SET fk_main_wastewater_node = ws_nodes.wn_obj_id | ||
FROM ( | ||
SELECT ws.obj_id, min(wn.obj_id) OVER (PARTITION BY ws.obj_id) AS wn_obj_id | ||
FROM qgep_od.wastewater_structure ws | ||
LEFT JOIN qgep_od.wastewater_networkelement ne ON ne.fk_wastewater_structure = ws.obj_id | ||
LEFT JOIN qgep_od.wastewater_node wn ON ne.obj_id = wn.obj_id | ||
LEFT JOIN qgep_od.channel ch ON ch.obj_id = ws.obj_id | ||
WHERE ch.obj_id IS NULL AND (_all OR ws.obj_id = _obj_id OR ( NOT _all AND _obj_id is NULL AND ws.fk_main_wastewater_node IS NULL)) | ||
) ws_nodes | ||
WHERE ws.obj_id = ws_nodes.obj_id; | ||
END | ||
|
||
$BODY$ | ||
LANGUAGE plpgsql | ||
VOLATILE; |