Skip to content

Instantly share code, notes, and snippets.

@vnegi10
Last active July 15, 2023 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vnegi10/3fd1857e99d5b9a3a834473c1029fc9e to your computer and use it in GitHub Desktop.
Save vnegi10/3fd1857e99d5b9a3a834473c1029fc9e to your computer and use it in GitHub Desktop.
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