Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id C342E384476 for ; Thu, 8 Dec 2011 06:10:29 -0400 (AST) Received: from mailout-de.gmx.net ([213.165.64.22]) by makus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1RYavp-0008Uh-5E for pgsql-sql@postgresql.org; Thu, 08 Dec 2011 10:10:30 +0000 Received: (qmail invoked by alias); 08 Dec 2011 10:10:11 -0000 Received: from mue-88-130-5-014.dsl.tropolys.de (EHLO [192.168.1.113]) [88.130.5.14] by mail.gmx.net (mp062) with SMTP; 08 Dec 2011 11:10:11 +0100 X-Authenticated: #14269776 X-Provags-ID: V01U2FsdGVkX1/NvVI+/g7NraYNQBWbWODo2Bxa6LNSr6sppmEdy0 ZkO99ncLD/ZKyx Message-ID: <4EE08CFE.3090209@gmx.net> Date: Thu, 08 Dec 2011 11:10:06 +0100 From: Andreas User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 To: Emre Hasegeli CC: pgsql-sql@postgresql.org Subject: Re: Question on imports with foreign keys References: <4EE05DD3.2080308@gmx.net> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-Pg-Spam-Score: -3.1 (---) X-Archive-Number: 201112/28 X-Sequence-Number: 36089 Am 08.12.2011 09:39, schrieb Emre Hasegeli: > On Thu, 08 Dec 2011 08:48:51 +0200, Andreas wrote: > >> How is the easiest way to to find the customer.id of the new >> customers so I can insert the projectinfos? >> > > It is easy to select rows not related with another table. One of the > following queries can be used. > >> Select * from "customers" where id not in (select "customerId" from >> "projectinfos") > I'm sorry I wasn't clear enough describing the scenario. Lets's say there were already 1000 records in the customers table. Now I add 357 new customers to this table. If I use one of your queries I'd get all 1357 entries of customers since "project_x.projectinfos" would be newly created for this project and therefor empty. I need to know which customers.id was created for which line in the temporary table that I read in with copy. When I have those ids I can fill "project_x.projectinfos" with just those new 357 customer.ids and foreign keys refering the new lookup-tables.