Last active
July 15, 2023 20:49
-
-
Save vnegi10/3fd1857e99d5b9a3a834473c1029fc9e to your computer and use it in GitHub Desktop.
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
function remove_duplicate_fruits(db_name::String, table_name::String) | |
conn_db = connect_db(db_name) | |
# Remove duplicate rows using a common table expression (cte) | |
try | |
DBInterface.execute(conn_db, | |
"WITH cte AS ( | |
SELECT | |
Name, | |
Price, | |
Origin, | |
ROW_NUMBER() OVER ( | |
PARTITION BY | |
Name | |
ORDER BY | |
Name | |
) row_num FROM $table_name ) | |
DELETE FROM cte WHERE row_num > 1" ) | |
catch | |
error("Unable to delete rows!") | |
finally | |
DBInterface.close!(conn_db) | |
end | |
return nothing | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment