I'd do it as an UPDATE query with a SELECT subquery similar to what was done [here](https://github.com/joomla/joomla-cms/blob/staging/administrator/components/com_admin/sql/updates/postgresql/3.2.2-2013-12-28.sql)