-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LANTERN-595, LANTERN-596: Removal and prevention of duplicate rows in…
… healthit_products_map
- Loading branch information
1 parent
64e3c6c
commit 5341440
Showing
2 changed files
with
565 additions
and
544 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
db/migration/migrations/000028_remove_duplicates_healthit_products_map.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
BEGIN; | ||
|
||
|
||
CREATE OR REPLACE FUNCTION delete_duplicate_data_in_healthit_products_map() RETURNS VOID as $$ | ||
BEGIN | ||
WITH CTE AS ( | ||
SELECT | ||
ctid, | ||
ROW_NUMBER() OVER(PARTITION BY id, healthit_product_id ORDER BY id) AS DuplicateCount | ||
FROM | ||
public.healthit_products_map | ||
) | ||
DELETE FROM public.healthit_products_map | ||
WHERE ctid IN ( | ||
SELECT ctid | ||
FROM CTE | ||
WHERE DuplicateCount > 1 | ||
); | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
SELECT delete_duplicate_data_in_healthit_products_map(); | ||
|
||
COMMIT; |
Oops, something went wrong.