Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 266BD9FB2C4 for ; Tue, 6 Feb 2007 18:16:07 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 44991-08 for ; Tue, 6 Feb 2007 18:15:59 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from rrmailscan3.safenetbox.biz (unknown [203.25.40.75]) by postgresql.org (Postfix) with ESMTP id 2493E9FB2BE for ; Tue, 6 Feb 2007 18:15:59 -0400 (AST) Received: from rrmailscan3.safenetbox.biz (rrmailscan3.safenetbox.biz [127.0.0.1]) by rrmailscan3.safenetbox.biz (Postfix) with ESMTP id 8E5941D4843A for ; Wed, 7 Feb 2007 09:15:59 +1100 (EST) Received: from [172.17.2.14] (online4-new.lnk.telstra.net [139.130.169.227]) (Authenticated sender: remote) by rrmailscan3.safenetbox.biz (Postfix) with ESMTP id 9452D1D48424 for ; Wed, 7 Feb 2007 09:15:58 +1100 (EST) Message-ID: <45C8FDE6.6050603@autoledgers.com.au> Date: Wed, 07 Feb 2007 07:15:02 +0900 From: Paul Lambert User-Agent: Thunderbird 1.5.0.8 (Windows/20061025) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Removing duplicate rows Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200702/55 X-Sequence-Number: 27389 I have some tables which I need to load from flat data files that can contain upwards of five million rows. It's possible (owing to the structure of the system the data is originating from) that on occasion the data extract that generates these flat files can include two records that have the same values in the fields that make up the primary key of the table in my Postgres database, thus throwing an error when I attempt to load. I'm assuming the best way to get around this is to load the data into a temporary table with "copy from" and then do a "select distinct into" my real table. The question I have is the best way to set up this temporary table in my reload script. (Having 14 servers running Postgres, each with 37 tables, I don't want to be creating temporary tables manually each time I need to reload the databases) As the table definitions get updated frequently, I'd like to put in my script to create the table as a copy of the existing 'real' table. I'm assuming "create table as" would be what I need to use, but what would I use as the select sql - i.e. how do I use select to pull the definition of a table. Apologies if this is a stupid question, I'm still fairly new to Postgres so I'm not sure what system tables are available for pulling out this kind of information. Thanks in advance for any assistance you can offer. Regards, Paul. -- Paul Lambert Database Administrator AutoLedgers