Skip to content

Commit

Permalink
enhan(filtered views): Last enhancement for filtered views
Browse files Browse the repository at this point in the history
  • Loading branch information
xtorret committed Dec 30, 2024
1 parent 9dcb80c commit da6b0a4
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 39 deletions.
44 changes: 28 additions & 16 deletions updates/36/36017/ud/ddlview.sql
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,10 @@ WITH
(
SELECT node.node_id
FROM node
JOIN selector_expl se ON (se.cur_user =current_user AND se.expl_id = node.expl_id) or (se.cur_user = current_user AND se.expl_id = node.expl_id2)
JOIN selector_state s ON s.cur_user =current_user AND node.state =s.state_id
left JOIN (SELECT node_id FROM node_psector WHERE p_state = 0) a using (node_id) where a.node_id is null
union all
SELECT node_id FROM node_psector WHERE p_state = 11
SELECT node_id FROM node_psector WHERE p_state = 1
),
node_selected AS
(
Expand Down Expand Up @@ -267,7 +266,9 @@ WITH
node.serial_number
FROM node_selector
join node using (node_id)
JOIN cat_node ON node.nodecat_id::text = cat_node.id::text
JOIN selector_expl se ON (se.cur_user =current_user AND se.expl_id = node.expl_id) or (se.cur_user = current_user AND se.expl_id = node.expl_id2)
JOIN selector_sector sc ON (sc.cur_user = CURRENT_USER AND sc.sector_id = node.sector_id)
JOIN cat_node ON node.nodecat_id::text = cat_node.id::text
JOIN cat_feature ON cat_feature.id::text = node.node_type::text
JOIN exploitation ON node.expl_id = exploitation.expl_id
JOIN ext_municipality mu ON node.muni_id = mu.muni_id
Expand Down Expand Up @@ -313,7 +314,6 @@ AS WITH
(
SELECT arc.arc_id
FROM arc
JOIN selector_expl se ON ((se.cur_user = CURRENT_USER AND se.expl_id = arc.expl_id) OR (se.cur_user = CURRENT_USER and se.expl_id = arc.expl_id2))
JOIN selector_state s ON s.cur_user = CURRENT_USER AND arc.state = s.state_id
left JOIN (SELECT arc_id FROM arc_psector WHERE p_state = 0) a using (arc_id) where a.arc_id is null
union all
Expand Down Expand Up @@ -477,6 +477,8 @@ AS WITH
arc.serial_number
FROM arc_selector
JOIN arc using (arc_id)
JOIN selector_expl se ON (se.cur_user =current_user AND se.expl_id = arc.expl_id) or (se.cur_user = current_user AND se.expl_id = arc.expl_id2)
JOIN selector_sector sc ON (sc.cur_user = CURRENT_USER AND sc.sector_id = arc.sector_id)
JOIN cat_arc ON arc.arccat_id::text = cat_arc.id::text
JOIN cat_feature ON arc.arc_type::text = cat_feature.id::text
JOIN exploitation e on e.expl_id = arc.expl_id
Expand Down Expand Up @@ -526,18 +528,21 @@ with
),
connec_psector AS
(
SELECT pp.connec_id, pp.psector_id, pp.state AS p_state, FIRST_VALUE(pp.arc_id) OVER (PARTITION BY pp.connec_id, pp.state ORDER BY link_id DESC NULLS LAST, arc_id::int DESC NULLS LAST) AS arc_id
SELECT pp.connec_id, pp.psector_id, pp.state AS p_state,
FIRST_VALUE(pp.link_id) OVER (PARTITION BY pp.connec_id, pp.state ORDER BY link_id DESC NULLS LAST, arc_id::int DESC NULLS LAST) AS link_id,
FIRST_VALUE(pp.arc_id) OVER (PARTITION BY pp.connec_id, pp.state ORDER BY link_id DESC NULLS LAST, arc_id::int DESC NULLS LAST) AS arc_id
FROM plan_psector_x_connec pp
JOIN selector_psector sp ON sp.cur_user = current_user AND sp.psector_id = pp.psector_id
),
connec_selector AS
(
SELECT connec_id, arc_id FROM connec
JOIN selector_expl se ON (se.cur_user =current_user AND se.expl_id = connec.expl_id) or (se.cur_user =current_user and se.expl_id = connec.expl_id2)
SELECT connec_id, arc_id, NULL::integer as link_id
FROM connec
JOIN selector_state ss ON ss.cur_user =current_user AND connec.state =ss.state_id
left join (SELECT connec_id, arc_id::varchar(16) FROM connec_psector WHERE p_state = 0) a using (connec_id, arc_id) where a.connec_id is null
left join (SELECT connec_id, arc_id FROM connec_psector WHERE p_state = 0) a using (connec_id, arc_id) where a.connec_id is null
union all
SELECT connec_id, arc_id::varchar(16) FROM connec_psector WHERE p_state = 1
SELECT DISTINCT connec_id, connec_psector.arc_id, link_id FROM connec_psector
WHERE p_state = 1
),
connec_selected AS
(
Expand Down Expand Up @@ -657,6 +662,8 @@ with
connec.access_type
FROM connec_selector
JOIN connec USING (connec_id)
JOIN selector_expl se ON (se.cur_user =current_user AND se.expl_id = connec.expl_id) or (se.cur_user =current_user and se.expl_id = connec.expl_id2)
JOIN selector_sector sc ON (sc.cur_user = CURRENT_USER AND sc.sector_id = connec.sector_id)
JOIN cat_connec ON cat_connec.id::text = connec.connecat_id::text
JOIN cat_feature ON cat_feature.id::text = connec.connec_type::text
JOIN exploitation ON connec.expl_id = exploitation.expl_id
Expand All @@ -665,7 +672,7 @@ with
JOIN sector_table on sector_table.sector_id = connec.sector_id
left join dma_table on dma_table.dma_id = connec.dma_id
left join drainzone_table ON connec.dma_id = drainzone_table.drainzone_id
left join link_planned on connec.connec_id = feature_id
left join link_planned using (link_id)
)
SELECT connec_selected.*
FROM connec_selected;
Expand Down Expand Up @@ -711,19 +718,22 @@ with
),
gully_psector AS
(
SELECT pp.gully_id, pp.psector_id, pp.state AS p_state, FIRST_VALUE(pp.arc_id) OVER (PARTITION BY pp.gully_id, pp.state ORDER BY link_id DESC NULLS LAST, arc_id::int DESC NULLS LAST) AS arc_id
SELECT pp.gully_id, pp.psector_id, pp.state AS p_state,
FIRST_VALUE(pp.link_id) OVER (PARTITION BY pp.gully_id, pp.state ORDER BY link_id DESC NULLS LAST, arc_id::int DESC NULLS LAST) AS link_id,
FIRST_VALUE(pp.arc_id) OVER (PARTITION BY pp.gully_id, pp.state ORDER BY link_id DESC NULLS LAST, arc_id::int DESC NULLS LAST) AS arc_id
FROM plan_psector_x_gully pp
JOIN selector_psector sp ON sp.cur_user = current_user AND sp.psector_id = pp.psector_id
),
gully_selector AS
(
SELECT gully_id, arc_id FROM gully
JOIN selector_expl se ON (se.cur_user = current_user AND se.expl_id=gully.expl_id) OR (se.cur_user = current_user AND se.expl_id=gully.expl_id2)
SELECT gully_id, arc_id::varchar(16), null::integer as link_id
FROM gully
JOIN selector_state ss ON ss.cur_user =current_user AND gully.state =ss.state_id
left join (SELECT gully_id, arc_id::varchar(16) FROM gully_psector WHERE p_state = 0) a using (gully_id, arc_id) where a.gully_id is null
left join (SELECT gully_id, arc_id FROM gully_psector WHERE p_state = 0) a using (gully_id, arc_id) where a.gully_id is null
union all
SELECT gully_id, arc_id::varchar(16) FROM gully_psector WHERE p_state = 1
),
SELECT DISTINCT gully_id, gully_psector.arc_id::varchar(16), link_id FROM gully_psector
WHERE p_state = 1
),
gully_selected AS
(
SELECT gully.gully_id,
Expand Down Expand Up @@ -862,6 +872,8 @@ with
gully.the_geom
FROM inp_network_mode, gully_selector
JOIN gully using (gully_id)
JOIN selector_expl se ON (se.cur_user = current_user AND se.expl_id=gully.expl_id) OR (se.cur_user = current_user AND se.expl_id=gully.expl_id2)
JOIN selector_sector sc ON (sc.cur_user = CURRENT_USER AND sc.sector_id = gully.sector_id)
JOIN cat_grate ON gully.gratecat_id::text = cat_grate.id::text
JOIN exploitation ON gully.expl_id = exploitation.expl_id
JOIN cat_feature ON gully.gully_type::text = cat_feature.id::text
Expand Down
59 changes: 36 additions & 23 deletions updates/36/36017/ws/ddlview.sql
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ WITH
node_selector AS
(
SELECT node_id
FROM node
JOIN selector_expl se ON (se.cur_user =current_user AND se.expl_id = node.expl_id) or (se.cur_user = current_user AND se.expl_id = node.expl_id2)
FROM node
JOIN selector_state s ON s.cur_user =current_user AND node.state =s.state_id
LEFT JOIN (SELECT node_id FROM node_psector WHERE p_state = 0) a using (node_id) where a.node_id is null
union all
SELECT node_id FROM node_psector WHERE p_state = 1
SELECT node_id FROM node_psector
WHERE p_state = 1
),
node_selected AS
( SELECT node.node_id,
Expand Down Expand Up @@ -264,9 +264,12 @@ WITH
ELSE NULL::character varying(16)
END AS inp_type,
m.closed as closed_valve,
m.broken as broken_valve
m.broken as broken_valve,
sector_table.stylesheet ->> 'featureColor'::text AS sector_style
FROM node_selector
JOIN node ON node.node_id = node_selector.node_id
JOIN selector_expl se ON (se.cur_user =current_user AND se.expl_id = node.expl_id) or (se.cur_user = current_user AND se.expl_id = node.expl_id2)
JOIN selector_sector sc ON (sc.cur_user = CURRENT_USER AND sc.sector_id = node.sector_id)
JOIN cat_node ON cat_node.id::text = node.nodecat_id::text
JOIN cat_feature ON cat_feature.id::text = cat_node.nodetype_id::text
JOIN value_state_type vst ON vst.id = node.state_type
Expand Down Expand Up @@ -315,17 +318,17 @@ AS WITH
(
SELECT pp.arc_id, pp.state AS p_state
FROM plan_psector_x_arc pp
JOIN selector_psector sp ON sp.cur_user = CURRENT_USER AND sp.psector_id = pp.psector_id
),
JOIN selector_psector sp ON sp.cur_user = CURRENT_USER AND sp.psector_id = pp.psector_id
),
arc_selector AS
(
SELECT arc.arc_id
FROM arc
JOIN selector_expl se ON ((se.cur_user = CURRENT_USER AND se.expl_id = arc.expl_id) OR (se.cur_user = CURRENT_USER and se.expl_id = arc.expl_id2))
FROM arc
JOIN selector_state s ON s.cur_user = CURRENT_USER AND arc.state = s.state_id
left JOIN (SELECT arc_id FROM arc_psector WHERE p_state = 0) a using (arc_id) where a.arc_id is null
union all
SELECT arc_id FROM arc_psector WHERE p_state = 0
SELECT arc_id FROM arc_psector
WHERE p_state = 1
),
arc_selected AS (
SELECT arc.arc_id,
Expand Down Expand Up @@ -445,9 +448,12 @@ AS WITH
CASE
WHEN arc.sector_id > 0 AND vst.is_operative = true AND arc.epa_type::text <> 'UNDEFINED'::character varying(16)::text THEN arc.epa_type
ELSE NULL::character varying(16)
END AS inp_type
END AS inp_type,
sector_table.stylesheet ->> 'featureColor'::text AS sector_style
FROM arc_selector
JOIN arc ON arc.arc_id::text = arc_selector.arc_id::text
JOIN arc ON arc.arc_id::text = arc_selector.arc_id::text
JOIN selector_expl se ON ((se.cur_user = CURRENT_USER AND se.expl_id = arc.expl_id) OR (se.cur_user = CURRENT_USER and se.expl_id = arc.expl_id2))
JOIN selector_sector sc ON (sc.cur_user = CURRENT_USER AND sc.sector_id = arc.sector_id)
JOIN cat_arc ON cat_arc.id::text = arc.arccat_id::text
JOIN cat_feature ON cat_feature.id::text = cat_arc.arctype_id::text
JOIN exploitation ON arc.expl_id = exploitation.expl_id
Expand Down Expand Up @@ -511,19 +517,21 @@ WITH
),
connec_psector AS
(
SELECT pp.connec_id, pp.psector_id, pp.state AS p_state, FIRST_VALUE(pp.arc_id) OVER (PARTITION BY pp.connec_id, pp.state ORDER BY link_id DESC NULLS LAST, arc_id::int DESC NULLS LAST) AS arc_id
SELECT pp.connec_id, pp.psector_id, pp.state AS p_state,
FIRST_VALUE(pp.link_id) OVER (PARTITION BY pp.connec_id, pp.state ORDER BY link_id DESC NULLS LAST, arc_id::int DESC NULLS LAST) AS link_id,
FIRST_VALUE(pp.arc_id) OVER (PARTITION BY pp.connec_id, pp.state ORDER BY link_id DESC NULLS LAST, arc_id::int DESC NULLS LAST) AS arc_id
FROM plan_psector_x_connec pp
JOIN selector_psector sp ON sp.cur_user = current_user AND sp.psector_id = pp.psector_id
),
connec_selector AS
(
SELECT connec_id, arc_id
FROM connec
JOIN selector_expl se ON (se.cur_user =current_user AND se.expl_id = connec.expl_id) or (se.cur_user =current_user and se.expl_id = connec.expl_id2)
SELECT connec_id, arc_id::varchar(16), null::integer as link_id
FROM connec
JOIN selector_state ss ON ss.cur_user =current_user AND connec.state =ss.state_id
left join (SELECT connec_id, arc_id FROM connec_psector WHERE p_state = 0) a using (connec_id, arc_id) where a.connec_id is null
union all
SELECT connec_id, arc_id::varchar(16) FROM connec_psector WHERE p_state = 1
SELECT DISTINCT connec_id, connec_psector.arc_id::varchar(16), link_id FROM connec_psector
WHERE p_state = 1
),
connec_selected AS
(
Expand Down Expand Up @@ -616,7 +624,7 @@ WITH
connec.customer_code,
connec.connec_length,
connec.n_hydrometer,
connec.arc_id,
connec_selector.arc_id,
connec.annotation,
connec.observ,
connec.comment,
Expand Down Expand Up @@ -718,9 +726,12 @@ WITH
connec.insert_user,
date_trunc('second'::text, connec.lastupdate) AS lastupdate,
connec.lastupdate_user,
connec.the_geom
FROM inp_network_mode, connec_selector nn
JOIN connec ON connec.connec_id = nn.connec_id
connec.the_geom,
sector_table.stylesheet ->> 'featureColor'::text AS sector_style
FROM inp_network_mode, connec_selector
JOIN connec ON connec.connec_id = connec_selector.connec_id
JOIN selector_expl se ON (se.cur_user =current_user AND se.expl_id = connec.expl_id) or (se.cur_user =current_user and se.expl_id = connec.expl_id2)
JOIN selector_sector sc ON (sc.cur_user = CURRENT_USER AND sc.sector_id = connec.sector_id)
JOIN cat_connec ON cat_connec.id::text = connec.connecat_id::text
JOIN cat_feature ON cat_feature.id::text = cat_connec.connectype_id::text
JOIN exploitation ON connec.expl_id = exploitation.expl_id
Expand All @@ -730,7 +741,7 @@ WITH
LEFT JOIN dma_table ON dma_table.dma_id = connec.dma_id
LEFT JOIN dqa_table ON dqa_table.dqa_id = connec.dqa_id
LEFT JOIN crm_zone ON crm_zone.id::text = connec.crmzone_id::text
LEFT JOIN link_planned on connec.connec_id = feature_id
LEFT JOIN link_planned using (link_id)
LEFT JOIN connec_add e ON e.connec_id::text = connec.connec_id::text
LEFT JOIN value_state_type vst ON vst.id = connec.state_type
)
Expand Down Expand Up @@ -784,7 +795,8 @@ WITH
JOIN selector_state s ON s.cur_user =current_user AND l.state =s.state_id
left join (SELECT link_id FROM link_psector WHERE p_state = 0) a using (link_id) where a.link_id is null
UNION ALL
SELECT link_id FROM link_psector WHERE p_state = 1
SELECT link_id FROM link_psector
WHERE p_state = 1
),
link_selected as
(
Expand Down Expand Up @@ -838,7 +850,8 @@ WITH
END AS inp_type
FROM inp_network_mode, link_selector
JOIN link l using (link_id)
JOIN selector_expl se ON ((se.cur_user =current_user AND se.expl_id = l.expl_id) or (se.cur_user =current_user AND se.expl_id = l.expl_id2))
JOIN selector_expl se ON ((se.cur_user =current_user AND se.expl_id = l.expl_id) or (se.cur_user =current_user AND se.expl_id = l.expl_id2))
JOIN selector_sector sc ON (sc.cur_user = CURRENT_USER AND sc.sector_id = l.sector_id)
JOIN sector_table ON sector_table.sector_id = l.sector_id
LEFT JOIN presszone_table ON presszone_table.presszone_id = l.presszone_id
LEFT JOIN dma_table ON dma_table.dma_id = l.dma_id
Expand Down

0 comments on commit da6b0a4

Please sign in to comment.