Skip to content

Instantly share code, notes, and snippets.

@jotes
Last active March 10, 2018 01:55
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 jotes/d2c277a80913dc76c4f0b3005acf16ab to your computer and use it in GitHub Desktop.
Save jotes/d2c277a80913dc76c4f0b3005acf16ab to your computer and use it in GitHub Desktop.
-- That query gives you a list of duplicates without the first record
-- you can delete them later
with d as (
select entity_id, locale_id, t.string, count(t.id) as duplicates,
array_agg(t.id order by approved desc, rejected asc, date desc) as ids
from base_translation t
join base_entity e
ON (t.entity_id=e.id)
join base_resource r
ON (e.resource_id=r.id)
WHERE r.path like '%.ftl'
group by locale_id, entity_id, t.string
order by count(t.id) desc
)
SELECT unnest(ids[2:100]) from d;
-- The same query but with DELETE statement, may require additional cleanups in translationmemoryentry table though
with d as (
select entity_id, locale_id, t.string, count(t.id) as duplicates,
array_agg(t.id order by approved desc, rejected asc, date desc) as ids
from base_translation t
join base_entity e
ON (t.entity_id=e.id)
join base_resource r
ON (e.resource_id=r.id)
WHERE r.path like '%.ftl'
group by locale_id, entity_id, t.string
order by count(t.id) desc
)
DELETE FROM base_translation WHERE id IN (SELECT unnest(ids[2:100]) from d);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment