Remap error when a post contains a quote from another topic

When I enter a remap command as per Change the domain name or rename your Discourse, I’m getting this error whenever a topic contains a quote from another topic:

Error: ERROR: duplicate key value violates unique constraint “unique_post_links”
DETAIL: Key (topic_id, post_id, url)=(265, 33103, already exists.
The remap has only been partially applied due to the error above. Please re-run the script again.

This situation occurs when posts containing a quote are split off into a different topic, or if they have been deliberately made.

If I permanently delete the offending topic or remove the quote reference manually, it is all good. But that isn’t really feasible.