I have a table with organization_id and name columns. I need to add a composite unique index to those columns, but we have some duplicate names that need to be updated. I can find the offending records with this query:
with cte as (select l.id, t.*
from locations l
join (
select name, organization_id, count(*) as qty
from locations
group by name, organization_id
having count(*) > 1
) t on l.name = t.name and l.organization_id = t.organization_id )
I would like to update the records by appending some some incrementing values to the names (this isn't production data, don't judge me :D).
something like
update locations
set name = locations.name || (select i from generate_series(1..some_count))::text
from cte