X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 1DAB8D1C94C for ; Thu, 14 Aug 2003 17:53:55 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 10154-01 for ; Thu, 14 Aug 2003 14:53:41 -0300 (ADT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id 5C287D1F60E for ; Thu, 14 Aug 2003 14:40:35 -0300 (ADT) Received: (qmail 13042 invoked by uid 500); 14 Aug 2003 17:46:07 -0000 Date: Thu, 14 Aug 2003 12:46:07 -0500 From: Bruno Wolff III To: expect Cc: pgsql-general@postgresql.org Subject: Re: importing db as text files Message-ID: <20030814174607.GA11966@wolff.to> Mail-Followup-To: expect , pgsql-general@postgresql.org References: <20030813141420.1db05267.expect@ihubbell.com> <20030813213004.GA27062@wolff.to> <20030813204555.755edd6b.expect@ihubbell.com> <20030814134520.GC27870@wolff.to> <20030814090816.35ebe809.expect@ihubbell.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030814090816.35ebe809.expect@ihubbell.com> User-Agent: Mutt/1.5.4i X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/696 X-Sequence-Number: 47113 On Thu, Aug 14, 2003 at 09:08:16 -0700, expect wrote: > > 191922C,Bob Cobb,D'Obbalina Sr.,312 Elm Street,Yountville,CA,94599,5,062001,082009 > 339111C,Elma Thelma,Velma,98 Oak Lane,St. Louis,MO,63119-2065,,, That should be handled by copy pretty easily. If the columns after what appears to be the zip code are some type of number rather than a string, then the empty string is going to be an invalid value. If you want the empty string to be interpreted as the default and you don't have any NULL values in your input, then the simplest thing to do is set the code for NULLs to be the empty string. You can then do queries after the data is in the database to change the NULLs to the appropiate default. If you are running the 7.4 beta you can use the DEFAULT key in the update, otherwise you will need to duplicate the default expression in the update commands. You will want to run update once for each column that can have NULL values using IS NULL in the WHERE clause. If these columns have a NOT NULL constraint, you may want to use a temporary table to load the data and then copy it over (with a single insert statement) after it has been cleaned up. Note that it isn't obvious what empty strings should map to for numbers. NULL and 0 make about as much sense as using the default value.