X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6065F9DCB88 for ; Tue, 28 Mar 2006 11:57:18 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 92026-05 for ; Tue, 28 Mar 2006 11:57:23 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 543919DCBAF for ; Tue, 28 Mar 2006 11:57:16 -0400 (AST) Received: from linspr1.tempdomainname.com (linspr1.tempdomainname.com [161.58.246.140]) by svr4.postgresql.org (Postfix) with ESMTP id 4E2355AF85E for ; Tue, 28 Mar 2006 15:57:22 +0000 (GMT) Received: from [192.168.2.5] (ip-216-73-188-2.hqglobal.net [216.73.188.2]) by linspr1.tempdomainname.com (8.12.11.20060308/8.12.11) with ESMTP id k2SFvJWO029749 for ; Tue, 28 Mar 2006 08:57:19 -0700 (MST) From: ashah Organization: opus To: pgsql-performance@postgresql.org Subject: Re: Massive Inserts Strategies Date: Tue, 28 Mar 2006 10:59:49 -0500 User-Agent: KMail/1.8.2 References: <200603221032.10207.ashah@opuspro.com> <20060322160924.GJ15742@pervasive.com> In-Reply-To: <20060322160924.GJ15742@pervasive.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200603281059.49790.ashah@opuspro.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200603/543 X-Sequence-Number: 17980 I tried this solution, but ran into following problem. The temp_table has columns (col1, col2, col3). The original_table has columns (col0, col1, col2, col3) Now the extra col0 on the original_table is the unique generated ID by the database. How can I make your suggestions work in that case .. ? On Wednesday 22 March 2006 11:09 am, Jim C. Nasby wrote: > Load the files into a temp table and go from there... > > COPY ... FROM file; > UPDATE existing_table SET ... WHERE ...; > INSERT INTO existing_table SELECT * FROM temp_table WHERE NOT EXISTS( > SELECT * FROM existing_table WHERE ...) > > On Wed, Mar 22, 2006 at 10:32:10AM -0500, ashah wrote: > > I have a database with foreign keys enabled on the schema. I receive > > different files, some of them are huge. And I need to load these files in > > the database every night. There are several scenerios that I want to > > design an optimal solution for - > > > > 1. One of the file has around 80K records and I have to delete everything > > from the table and load this file. The provider never provides a "delta > > file" so I dont have a way to identify which records are already present > > and which are new. If I dont delete everything and insert fresh, I have > > to make around 80K selects to decide if the records exist or not. Now > > there are lot of tables that have foreign keys linked with this table so > > unless I disable the foreign keys, I cannot really delete anything from > > this table. What would be a good practise here? > > > > 2. Another file that I receive has around 150K records that I need to > > load in the database. Now one of the fields is logically a "foreign key" > > to another table, and it is linked to the parent table via a database > > generated unique ID instead of the actual value. But the file comes with > > the actual value. So once again, I have to either drop the foreign key, > > or make 150K selects to determine the serial ID so that the foreign key > > is satisfied. What would be a good strategy in this scenerio ? > > > > Please pardon my inexperience with database ! > > > > Thanks, > > Amit > > > > ---------------------------(end of broadcast)--------------------------- > > TIP 4: Have you searched our list archives? > > > > http://archives.postgresql.org