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 3DC379FA387 for ; Sat, 20 May 2006 21:54:53 -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 13158-02 for ; Sat, 20 May 2006 21:54:48 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web52504.mail.yahoo.com (web52504.mail.yahoo.com [206.190.48.187]) by postgresql.org (Postfix) with SMTP id CDCA99F9316 for ; Sat, 20 May 2006 21:54:48 -0300 (ADT) Received: (qmail 99477 invoked by uid 60001); 21 May 2006 00:54:47 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=WqCfqtdVorPrcNdHkc2J8SHq0h4RRgMTmKF1ht/8lpweokDEkodbhlNcLcd6xY3VIz09ET2jNY9s7SmOgkFsA/mEIYoIa+YS3s2UKpIeQsMa15jYZ58ly+LTpODOCXqS/QCNkXFIOvNZyO5CuJxJcFPUH3XsgUF2SwBo4547v6E= ; Message-ID: <20060521005447.99475.qmail@web52504.mail.yahoo.com> Received: from [141.157.85.33] by web52504.mail.yahoo.com via HTTP; Sat, 20 May 2006 17:54:47 PDT Date: Sat, 20 May 2006 17:54:47 -0700 (PDT) From: Ash Grove Subject: Re: insert related data into two tables To: pgsql-sql@postgresql.org In-Reply-To: <1147642849.180115.107460@u72g2000cwu.googlegroups.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/157 X-Sequence-Number: 25188 You need to manage the transaction: begin a transaction, execute your first insert, retrieve the ID with curr_val(), execute the sencond insert and commit the transaction. --- 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 > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com