tww
.tww_app
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
wastewater_structure_update_fk_main_wastewater_node(_obj_id text DEFAULT NULL::text, _all boolean DEFAULT false)
Parameters
Name
Type
Mode
_obj_id
text
IN
_all
boolean
IN
Definition
DECLARE myrec record; BEGIN UPDATE tww_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 tww_od.wastewater_structure ws LEFT JOIN tww_od.wastewater_networkelement ne ON ne.fk_wastewater_structure = ws.obj_id LEFT JOIN tww_od.wastewater_node wn ON ne.obj_id = wn.obj_id LEFT JOIN tww_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