Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 52B77633F86 for ; Mon, 20 Jul 2009 21:31:29 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 23894-01-10 for ; Mon, 20 Jul 2009 21:31:18 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp.insa-lyon.fr (criges14.insa-lyon.fr [134.214.76.242]) by mail.postgresql.org (Postfix) with ESMTP id CD05C63500D for ; Mon, 20 Jul 2009 21:21:02 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by smtp.insa-lyon.fr (Postfix) with ESMTP id 0228FF1211; Tue, 21 Jul 2009 02:21:01 +0200 (CEST) X-Virus-Scanned: SMTP at INSA-LYON Received: from smtp.insa-lyon.fr ([127.0.0.1]) by localhost (criges14.insa-lyon.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yecwhj3-JXpS; Tue, 21 Jul 2009 02:21:00 +0200 (CEST) Received: from [127.0.0.1] (liris.univ-lyon1.fr [134.214.142.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: nhandrianar) by smtp.insa-lyon.fr (Postfix) with ESMTPSA id F3349F11FE; Tue, 21 Jul 2009 02:20:59 +0200 (CEST) Message-ID: <4A6509B7.7010400@free.fr> Date: Tue, 21 Jul 2009 02:20:07 +0200 From: nha Organization: Lyon, Rhone, France User-Agent: Thunderbird 2.0.0.6 (Macintosh/20070728) MIME-Version: 1.0 To: Chester C Young CC: =?UTF-8?B?TWFyY2luIFN0xJlwbmlja2k=?= , PgSQL-sql Subject: Re: unused columns in copy References: <471945.42509.qm@web54306.mail.re2.yahoo.com> <179149fe0907201559x3e81028aue0b51ba317c2fbbb@mail.gmail.com> In-Reply-To: <179149fe0907201559x3e81028aue0b51ba317c2fbbb@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200907/88 X-Sequence-Number: 32829 Hello, Le 21/07/09 0:59, Marcin Stępnicki a écrit : > On Mon, Jul 20, 2009 at 3:22 PM, chester c young wrote: >> is there a way for COPY FROM to ignore unused columns in CSV? >> >> in other words, if table t1 has columns c1, c2, and if csv has columns c1, c3, c2, could I do something like >> >> COPY t1( c1, null, c2 ) FROM 'file.csv' > > No, but you can use pgloader which can easily deal with your problem > and much more. http://pgfoundry.org/projects/pgloader/ > Depending on PostgreSQL version, copy restrictions may be performed (see also documentation of PostgreSQL 8.4): http://www.postgresql.org/docs/8.4/interactive/sql-copy.html Assuming that a CSV file contains data with column headers c1, c2, and c3, the following statement would retrieve only columns c1 and c2 from this file to a table t1: COPY t1(c1, c2) FROM '/path/to/file.csv'; Regards. -- nha / Lyon / France.