tww
.tww_app
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
wastewater_structure_update_fk_main_cover(_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_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 tww_od.wastewater_structure ws LEFT JOIN tww_od.structure_part sp ON sp.fk_wastewater_structure = ws.obj_id LEFT JOIN tww_od.cover co ON sp.obj_id = co.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_cover IS NULL)) ) ws_covers WHERE ws.obj_id = ws_covers.obj_id; END