From: Philippe Lang <philippe.lang@attiksystem.ch>
To: pgsql-sql@postgresql.org
Subject: SQL tree duplication
Date: Thu, 24 Jan 2008 10:42:26 +0100
Message-ID: <6C0CF58A187DA5479245E0830AF84F4218D00A@poweredge.attiksystem.ch> (raw)
Hi,
I have the following kind of sql structure, in 3 levels:
-----------------------
create table documents (
id serial,
name varchar(50),
primary key (id)
);
create table lines (
id serial,
name varchar(50),
document_id integer,
primary key (id),
foreign key (document_id) references documents (id)
);
create table line_details (
id serial,
name varchar(50),
line_id integer,
primary key (id),
foreign key (line_id) references lines (id)
);
-----------------------
I'd like to be able to "duplicate" a document, with all of its lines and
line details.
Is there any easy way to do that with Postgresql? The only solution I
can think of at the moment is to loop through all lines and line
details, and replace foreign keys properly with values fetch with
"currval". It should work just fine, but I was wondering if some
advanced features of Postgresql could help in this situation.
Regards,
Philippe Lang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: philippe.lang@attiksystem.ch
Subject: Re: SQL tree duplication
In-Reply-To: <6C0CF58A187DA5479245E0830AF84F4218D00A@poweredge.attiksystem.ch>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox