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 E9930D1C4D6 for ; Fri, 15 Aug 2003 10:11:48 +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 27523-04 for ; Fri, 15 Aug 2003 07:11:40 -0300 (ADT) Received: from mail022.syd.optusnet.com.au (mail022.syd.optusnet.com.au [210.49.20.149]) by svr1.postgresql.org (Postfix) with ESMTP id 64333D1B539 for ; Fri, 15 Aug 2003 07:11:36 -0300 (ADT) Received: from jerry (c210-49-244-235.thoms1.vic.optusnet.com.au [210.49.244.235]) by mail022.syd.optusnet.com.au (8.11.6p2/8.11.6) with ESMTP id h7FABaJ09245 for ; Fri, 15 Aug 2003 20:11:37 +1000 From: Jason Godden Reply-To: jasongodden@optushome.com.au To: pgsql-general@postgresql.org Subject: Re: importing db as text files Date: Fri, 15 Aug 2003 20:11:35 +1000 User-Agent: KMail/1.5 References: <20030814211528.02759176.expect@ihubbell.com> <20030815002727.Q9630-100000@megazone.bigpanda.com> <20030815005303.17eb4c7d.expect@ihubbell.com> In-Reply-To: <20030815005303.17eb4c7d.expect@ihubbell.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200308152011.35769.jasongodden@optushome.com.au> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/722 X-Sequence-Number: 47139 Whilst I agree with what Bruno said regarding adding a default option to the copy syntax I think that the basic principles Stephan and I outlined in how copy treats your import is correct and the developers did the right thing. Now if the devs, you or I want to add a default option to copy in the future thats all good but for the moment you will have to use some pre or post process to get the absolute effect you require. It's not that hard.. literally one line of piped commands on the command line where you specify the defaults or a post process that does the final import into your production tables from your data import table. Remember NULL != Default. These are VERY different concepts and I believe that enough examples of how this behaviour can lead to confusion have been shown. With copy it is also important to remember that is not part of the SQL standard and PG doesn't use SQL statements to do the import but rather a low-level C operation. If you need the behaviour you're referring to sed/awk the data up and generate BEGIN... INSERT... COMMIT... statements and pipe that to PG. It's not that difficult and I'll give you some suggestions with it if you want. I'm not trying to be difficult with my view of this but there are always other ways (sometimes one liners) that can achieve the behaviour you're after. Rgds, Jason On Fri, 15 Aug 2003 05:53 pm, you wrote: > On Fri, 15 Aug 2003 00:32:01 -0700 (PDT) > > Stephan Szabo wrote: > > On Thu, 14 Aug 2003, expect wrote: > > > On Thu, 14 Aug 2003 12:46:07 -0500 > > > > > > Bruno Wolff III wrote: > > > > 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. > > > > > > Well I'm new here but it seems to me they should map to the default > > > value for that column. Why wouldn't they? > > > > One problem with doing that is that it's inconsistent. > > Please elaborate. How is it inconsistent, exactly? > > > Given > > create table test( > > a text default 'abc', > > b int default 5 > > ); > > > > copy test from stdin with delimiter ','; > > , > > \. > > > > What would you expect the values of the row in test > > to be? > > Oh a test.... > > Does the \. end the STDIN input? > > Where's the null option? Don't you mean: > > copy test from stdin with delimiter ',' null ''; > > > In this case I would expect the row to have: > > a | b > ---------- > > abc | 5 > > > Is this too much to expect? > > > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 8: explain analyze is your friend