Skip to content

Instantly share code, notes, and snippets.

@chandeeland
Created January 7, 2015 19:07
Show Gist options
  • Save chandeeland/fcce7b12afa61ea40d52 to your computer and use it in GitHub Desktop.
Save chandeeland/fcce7b12afa61ea40d52 to your computer and use it in GitHub Desktop.
Dirty SQL Data Migration Technique
--
-- how to populate locations table on db2 from wineries table on db1
--
-- SELECT "INSERT INTO locations( name, website, address, address2, city, state, zip, country, phone, created_at, updated_at, latitude, longitude, email, fax, winery_id ) VALUES (" || name ||", " || website || ", " || address || ", null , null, null, null, null, " || phone || ", " || created_at || ", " || modified_at || ",null, null, " || email || ", " || fax || ", " || winery_id || "); " FROM wineries
SELECT 'INSERT INTO locations( name, winery_id ) VALUES ("' || name || '", "' || winery_id || '"); ' FROM wineries
--
-- pgsql [dbname] < dump_wineries.sql > output.sql
--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment