X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 0EC799F94EA for ; Mon, 22 May 2006 06:43:02 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 43763-01 for ; Mon, 22 May 2006 06:42:48 -0300 (ADT) X-Greylist: delayed 00:10:31.863431 by SQLgrey- Received: from smtp2.lc.anpe.fr (unknown [80.118.163.16]) by postgresql.org (Postfix) with ESMTP id EFAB59F946B for ; Mon, 22 May 2006 06:42:48 -0300 (ADT) Received: from HOMERE02.anpe.fr (amadeus [127.0.0.1]) by smtp2.lc.anpe.fr (antivirus) with ESMTP id 86B4F73D38; Mon, 22 May 2006 11:32:10 +0200 (CEST) Received: from [10.0.32.170] ([10.0.32.170]) by HOMERE02.anpe.fr with Microsoft SMTPSVC(6.0.3790.1830); Mon, 22 May 2006 11:31:03 +0200 Message-ID: <447184F0.1050603@anpe.fr> Date: Mon, 22 May 2006 11:31:28 +0200 From: Patrick JACQUOT User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: filippo2991@virgilio.it Cc: pgsql-sql@postgresql.org Subject: Re: insert related data into two tables References: <1147642849.180115.107460@u72g2000cwu.googlegroups.com> In-Reply-To: <1147642849.180115.107460@u72g2000cwu.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 22 May 2006 09:31:03.0730 (UTC) FILETIME=[71EE4920:01C67D82] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/166 X-Sequence-Number: 25197 filippo2991@virgilio.it wrote: >Hello, > >I have two tables like these: > >TABLE_1: people registry >fields: ID_T1, SURNAME, NAME >ID_T1 is primary key > >TABLE_2: work groups >fields: ID_T2, TASK >ID_T2 is foreign key related to ID_T1 > >the first table is the list of employees, the second the task. > >Sometime I need to insert a new employee and at the same time the task >for him: >I want to INSERT TO table 1 JOHN DOE (the ID is assigned automatically >since it's a primary key) and INSERT TO table 2 the ID and the task >name for JOHN DOE. Is it possible to create a single query? What is the >best way to do this? > >Thanks, > >Filippo > > >---------------------------(end of broadcast)--------------------------- >TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq > > > maybe you could create a view for the join of the two tebles, then make that view writable by creating the appropriate triggers. Then a single insert into the view would in fact create everything.