Skip to content

Commit

Permalink
enhan(views): Minor enhacement by using alias for window on width def…
Browse files Browse the repository at this point in the history
…initions
  • Loading branch information
xtorret committed Jan 2, 2025
1 parent 2460de7 commit ec9fb94
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
18 changes: 10 additions & 8 deletions updates/36/36017/ud/ddlview.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
(
Expand Down Expand Up @@ -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
(
Expand Down Expand Up @@ -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
),
Expand Down
13 changes: 7 additions & 6 deletions updates/36/36017/ws/ddlview.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
),
Expand Down

0 comments on commit ec9fb94

Please sign in to comment.