Re: copy row tree

From: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
To: "Richard Huxton" <dev(at)archonet(dot)com>
Cc: "Toni Casueps" <casueps(at)hotmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: copy row tree
Date: 2007-01-18 04:15:39
Message-ID: b42b73150701172015n7bb5a80ds80f0d2be69f81065@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 1/17/07, Richard Huxton <dev(at)archonet(dot)com> wrote:
> 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;

maybe there is:
set up RI triggers and set them to on update..cascade
add a trigger to each table which inserts into copy tables
if head table has p-key of id,

update main set id = id where id in (copy list);

:-)

merlin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message stevegy 2007-01-18 04:25:47 Re: &nbsp;&nbsp;The&nbsp;jdbc
Previous Message Ian Harding 2007-01-17 23:41:12 Re: [1/2 OFF] Varlena.com inaccessible from .br (Blocked?)