Re: copy row tree - Mailing list pgsql-general

From Richard Huxton
Subject Re: copy row tree
Date
Msg-id 45AE152A.5030501@archonet.com
Whole thread Raw
In response to copy row tree  ("Toni Casueps" <casueps@hotmail.com>)
Responses Re: copy row tree  ("Merlin Moncure" <mmoncure@gmail.com>)
List pgsql-general
Toni Casueps wrote:
>
> I have a set of tables with one-to-many relationships between them:
>
> T1 <-->> T2 <-->> T3 <-->> T4
>
> I need to copy some rows of these tables to another set of tables which
> have the same fields.

There's no shortcut.

BEGIN;
INSERT INTO copy_t1 SELECT * FROM t1 WHERE id IN (123, 456);
INSERT INTO copy_t2 SELECT * FROM t2 WHERE t2_t1_ref IN (SELECT id FROM
t1 WHERE id IN (123, 456));
INSERT INTO copy_t3 SELECT * FROM t3 WHERE t3_t2_ref IN (SELECT ... FROM
t2 WHERE ...)
...etc...
COMMIT;


--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Controlling memory of session
Next
From: "Alexi Gen"
Date:
Subject: Newbie questions (pg_global, tablespace, pg_temp, ...)