I am trying to eliminate duplicate subscribers from the subscribers table for a api_customer_id, this is the query that I use to get those duplicate subscribers :
select subscribers.email, count(*) from subscribers
inner join subscriptions on subscriptions.subscriber_id = subscribers.id
inner join subscription_lists on subscription_lists.id = subscriptions.subscription_list_id
where 793 in (subscribers.api_customer_id, subscription_lists.api_customer_id)
group by subscribers.email
having count(*) > 1
I tried to delete everything that is not max(subscribers.id), but I could not because the id column type is uuid
. Here is that error :
ERROR: function max(uuid) does not exist
LINE 1: select max(subscribers.id), subscribers.email, count(*) from...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
SQL state: 42883
Character: 8
What can I do in the meantime to get rid of the duplicates? There is created column on the subscribers, but the times are very close together that I'm fearful to use that to max/min on. Any other suggestions?
Update 1:
Per question in the comments I do have another column updated at too, they look like this :
But they're all in the same second, and it's still risky. I don't have the flexibility to change this design now, maybe I can going forward.