Skip to content

Instantly share code, notes, and snippets.

@gurneyalex
Created July 25, 2018 07:27
Show Gist options
  • Select an option

  • Save gurneyalex/1c9a7259636e98d2873074fc708afc0d to your computer and use it in GitHub Desktop.

Select an option

Save gurneyalex/1c9a7259636e98d2873074fc708afc0d to your computer and use it in GitHub Desktop.
-- in restored dump
COPY (
SELECT t.id, e.identification_id
FROM transport_order t JOIN hr_employee e ON (t.driver_id = e.id)
) TO '/tmp/transport.dat'
WITH (FORMAT binary);
-- in production database
CREATE TABLE tmp_transport (id INTEGER, driver VARCHAR);
COPY tmp_transport FROM '/tmp/transport.dat' WITH (FORMAT binary);
BEGIN;
UPDATE transport_order SET driver_id = tmp.employee_id
FROM (
SELECT t.id transport_id, e.id employee_id
FROM tmp_transport t JOIN hr_employee e on (e.identification_id = t.driver)
) tmp
WHERE id = tmp.transport_id;
-- check the result (not shown here)
COMMIT;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment