Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 9DB519FB340 for ; Thu, 8 Feb 2007 15:22:13 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 84154-01 for ; Thu, 8 Feb 2007 15:22:02 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from lists.commandprompt.com (host-254.commandprompt.net [207.173.203.254]) by postgresql.org (Postfix) with ESMTP id 744799FB355 for ; Thu, 8 Feb 2007 15:22:01 -0400 (AST) Received: from perhan.alvh.no-ip.org (200-126-100-50.bk7-dsl.surnet.cl [200.126.100.50]) (authenticated bits=0) by lists.commandprompt.com (8.13.7/8.13.6) with ESMTP id l18JLqkx019594; Thu, 8 Feb 2007 11:21:57 -0800 Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id C8A7C7DCA; Thu, 8 Feb 2007 16:21:49 -0300 (CLST) Date: Thu, 8 Feb 2007 16:21:49 -0300 From: Alvaro Herrera To: "Demel, Jeff" Cc: pgsql-sql@postgresql.org Subject: Re: COPY FROM - force a value Message-ID: <20070208192149.GY24069@alvh.no-ip.org> Mail-Followup-To: "Demel, Jeff" , pgsql-sql@postgresql.org References: <136ED738BD4F1545B97E4AC06FF6370734C296@DMSP-MSG-EVS01.mail.pvt> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <136ED738BD4F1545B97E4AC06FF6370734C296@DMSP-MSG-EVS01.mail.pvt> User-Agent: Mutt/1.5.13 (2006-08-11) X-Virus-Scanned: ClamAV version 0.88.5, clamav-milter version 0.88.5 on projects.commandprompt.com X-Virus-Status: Clean X-Greylist: Sender succeded SMTP AUTH authentication, not delayed by milter-greylist-1.6 (lists.commandprompt.com [192.168.2.159]); Thu, 08 Feb 2007 11:21:58 -0800 (PST) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.023 tagged_above=0 required=5 tests=AWL, BAYES_05, FORGED_RCVD_HELO, RCVD_IN_NJABL_PROXY, RCVD_IN_SORBS_SOCKS X-Spam-Level: X-Archive-Number: 200702/103 X-Sequence-Number: 27437 Demel, Jeff wrote: > Is there a way to force a value when you're doing a COPY FROM, importing > a file into a table? > > Here's my query as it is now: > > COPY filetable (value1, value2, value3, value4, forcevalue1, > forcevalue2) > FROM 'C:\\InsertFiles\\thisfile.txt' > WITH DELIMITER AS ' ' > ; > > The file only contains data for values 1 through 4. I'd like to insert > values for the last two fields. This is what I had in mind, which > doesn't work: > > COPY filetable (value1, value2, value3, value4, forcevalue1, > forcevalue2) > FROM 'C:\\InsertFiles\\thisfile.txt' > WITH DELIMITER AS ' ', > forcevalue1 = 1, > forcevalue2 = 'this value' > ; I'd try setting a DEFAULT for those two columns using ALTER TABLE, then the COPY FROM call excluding those columns, then removing the DEFAULT. If you do it in a transaction block, no other transaction can be molested by the default values, though they will be blocked of the table during that transaction. -- Alvaro Herrera http://www.CommandPrompt.com/ The PostgreSQL Company - Command Prompt, Inc.