From ec9fb94986518b3648c68580a5f2006c6e9373e1 Mon Sep 17 00:00:00 2001 From: Xavier Torret Date: Thu, 2 Jan 2025 19:29:31 +0100 Subject: [PATCH] enhan(views): Minor enhacement by using alias for window on width definitions --- updates/36/36017/ud/ddlview.sql | 18 ++++++++++-------- updates/36/36017/ws/ddlview.sql | 13 +++++++------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/updates/36/36017/ud/ddlview.sql b/updates/36/36017/ud/ddlview.sql index 58fbaf13f..08d24af56 100644 --- a/updates/36/36017/ud/ddlview.sql +++ b/updates/36/36017/ud/ddlview.sql @@ -529,10 +529,11 @@ with connec_psector AS ( 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 + FIRST_VALUE(pp.link_id) OVER w AS link_id, + FIRST_VALUE(pp.arc_id) OVER w 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 + WINDOW w AS (PARTITION BY pp.connec_id, pp.state ORDER BY insert_tstamp DESC) ), connec_selector AS ( @@ -717,12 +718,13 @@ with where l.state = 2 ), gully_psector AS - ( - 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 + ( + SELECT pp.gully_id, pp.psector_id, pp.state AS p_state, + FIRST_VALUE(pp.link_id) OVER w AS link_id, + FIRST_VALUE(pp.arc_id) OVER w 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 + WINDOW w AS (PARTITION BY pp.gully_id, pp.state ORDER BY insert_tstamp DESC) ), gully_selector AS ( @@ -918,12 +920,12 @@ WITH link_psector AS ( SELECT pp.connec_id AS feature_id, 'CONNEC' AS feature_type, pp.psector_id, pp.state AS p_state, pp.arc_id as arc_id_original, pp.link_id as link_id_original, - 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.link_id) OVER (PARTITION BY pp.connec_id, pp.state ORDER BY insert_tstamp DESC) AS link_id FROM plan_psector_x_connec pp JOIN selector_psector sp ON sp.cur_user = current_user AND sp.psector_id = pp.psector_id UNION ALL SELECT pp.gully_id AS feature_id, 'GULLY' AS feature_type, pp.psector_id, pp.state AS p_state, pp.arc_id as arc_id_original, pp.link_id as link_id_original, - 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.link_id) OVER (PARTITION BY pp.gully_id, pp.state ORDER BY insert_tstamp DESC) AS link_id FROM plan_psector_x_gully pp JOIN selector_psector sp ON sp.cur_user = current_user AND sp.psector_id = pp.psector_id ), diff --git a/updates/36/36017/ws/ddlview.sql b/updates/36/36017/ws/ddlview.sql index 21ba3008f..0d33712ae 100644 --- a/updates/36/36017/ws/ddlview.sql +++ b/updates/36/36017/ws/ddlview.sql @@ -518,10 +518,11 @@ WITH connec_psector AS ( 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 + FIRST_VALUE(pp.link_id) OVER w AS link_id, + FIRST_VALUE(pp.arc_id) OVER w 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 + WINDOW w AS (PARTITION BY pp.connec_id, pp.state ORDER BY insert_tstamp DESC) ), connec_selector AS ( @@ -674,11 +675,11 @@ WITH connec.num_value, CASE WHEN link_planned.link_id IS NULL THEN connec.pjoint_id - ELSE connec.arc_id + ELSE link_planned.exit_id END AS pjoint_id, CASE WHEN link_planned.link_id IS NULL THEN connec.pjoint_type - ELSE 'ARC'::character varying(16) + ELSE link_planned.exit_type END AS pjoint_type, connec.adate, connec.adescript, @@ -783,8 +784,8 @@ WITH ), link_psector AS ( - SELECT pp.connec_id AS feature_id, 'CONNEC' AS feature_type, 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 + SELECT pp.connec_id AS feature_id, 'CONNEC' AS feature_type, pp.psector_id, pp.state AS p_state, + FIRST_VALUE(pp.link_id) OVER (PARTITION BY pp.connec_id, pp.state ORDER BY insert_tstamp DESC) AS link_id FROM plan_psector_x_connec pp JOIN selector_psector sp ON sp.cur_user = current_user AND sp.psector_id = pp.psector_id ),