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 425EA9FA294 for ; Sun, 14 May 2006 18:41:00 -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 65568-06 for ; Sun, 14 May 2006 18:40:56 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id 3C3B19F944D for ; Sun, 14 May 2006 18:40:56 -0300 (ADT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id EA35F30CF6; Sun, 14 May 2006 23:40:54 +0200 (MET DST) From: filippo2991@virgilio.it X-Newsgroups: pgsql.sql Subject: insert related data into two tables Date: 14 May 2006 14:40:49 -0700 Organization: http://groups.google.com Lines: 25 Message-ID: <1147642849.180115.107460@u72g2000cwu.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Complaints-To: groups-abuse@google.com User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Media Center PC 3.0; .NET CLR 1.0.3705; InfoPath.1),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: u72g2000cwu.googlegroups.com; posting-host=82.48.85.106; posting-account=MMcEjg0AAAA--8UL7aBU2jn4y8fFaVqr To: pgsql-sql@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/124 X-Sequence-Number: 25155 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