Re: Moving Specific Data Across Schemas Including FKs

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: Cory Tucker <cory(dot)tucker(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Moving Specific Data Across Schemas Including FKs
Date: 2015-04-23 18:08:00
Message-ID: 55393500.5020205@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 23/04/2015 18:09, Cory Tucker wrote:
> I have the need to move a specific set of data from one schema to
> another. These schemas are on the same database instance and have all
> of the same relations defined. The SQL to copy data from one table is
> relatively straightforward:
>
> INSERT INTO schema_b.my_table
> SELECT * FROM schema_a.my_table WHERE ...
>
> What I am trying to figure out is that if I also have other relations
> that have foreign keys into the data I am moving, how would I also move
> the data from those relations and maintain the FK integrity?

I'd create the tables in the new schema without the FK constraints, copy
the data, then add the constraints afterwards.

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod(at)iol(dot)ie

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Raymond O'Donnell 2015-04-23 18:12:52 Re: Moving Specific Data Across Schemas Including FKs
Previous Message William Dunn 2015-04-23 17:52:53 Re: R: DB on mSATA SSD