Skip to content

Commit

Permalink
Normalize sp_name and res_type columns from hfj_spidx_* tables - adde…
Browse files Browse the repository at this point in the history
…d sql migration scripts
  • Loading branch information
volodymyr-korzh committed Feb 14, 2025
1 parent 58b6d93 commit ac39d4d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
WITH cte_min_id AS (
SELECT
hash_identity,
MIN(sp_id) AS min_sp_id
FROM {0} -- replace {0} with hfj_spidx_* table
WHERE hash_identity NOT IN (
SELECT hash_identity
FROM hfj_spidx_identity
)
GROUP BY hash_identity
)
INSERT INTO HFJ_SPIDX_IDENTITY (
sp_identity_id,
hash_identity,
res_type,
sp_name
)
SELECT
NEXT VALUE FOR seq_spidx_identity OVER (ORDER BY src.res_type, src.sp_name) AS sp_identity_id,
src.hash_identity,
src.res_type,
src.sp_name
FROM {0} AS src -- replace {0} with hfj_spidx_* table
JOIN cte_min_id AS cm
ON src.hash_identity = cm.hash_identity
AND src.sp_id = cm.min_sp_id
ORDER BY
src.res_type,
src.sp_name;


Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT
hash_identity,
MAX(sp_name) KEEP (DENSE_RANK FIRST ORDER BY sp_id) AS sp_name,
MAX(res_type) KEEP (DENSE_RANK FIRST ORDER BY sp_id) AS res_type
FROM hfj_spidx_token
GROUP BY hash_identity;
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
INSERT INTO HFJ_SPIDX_IDENTITY (
sp_identity_id,
hash_identity,
res_type,
sp_name
)
WITH cte_min_id AS (
SELECT
hash_identity,
MIN(sp_id) AS min_sp_id
FROM {0} -- replace {0} with hfj_spidx_* table
WHERE hash_identity NOT IN (
SELECT hash_identity
FROM hfj_spidx_identity
)
GROUP BY hash_identity
)
SELECT
nextval(''SEQ_SPIDX_IDENTITY'') AS sp_identity_id,
src.hash_identity,
src.res_type,
src.sp_name
FROM {0} AS src -- replace {0} with hfj_spidx_* table
JOIN cte_min_id AS cm
ON src.hash_identity = cm.hash_identity
AND src.sp_id = cm.min_sp_id
ORDER BY src.res_type, src.sp_name;

SELECT DISTINCT on (hash_identity)
hash_identity
FROM hfj_spidx_token

0 comments on commit ac39d4d

Please sign in to comment.