Re: COPY column order

From: Brent Wood <Brent(dot)Wood(at)niwa(dot)co(dot)nz>
To: MD33 <mdubosforum(at)yahoo(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: COPY column order
Date: 2012-05-07 19:26:22
Message-ID: B30242D206AB9543A3406649674DB4190D0E14CC@welwexmb01.niwa.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

You can specify the column order in the copy statement:

psql -d test -c "create table ttt (id serial primary key, name varchar(10), value int);"
echo "10|one" | psql -d test -c "copy ttt (value,name) from stdin with delimiter '|';"
psql -d test -c "select * from ttt;"
id | name | value
----+------+-------
1 | one | 10
(1 row)

HTH

Brent Wood

GIS/DBA consultant
NIWA
+64 (4) 4 386-0300
________________________________________
From: pgsql-general-owner(at)postgresql(dot)org [pgsql-general-owner(at)postgresql(dot)org] on behalf of MD33 [mdubosforum(at)yahoo(dot)com]
Sent: Tuesday, May 08, 2012 12:33 AM
To: pgsql-general(at)postgresql(dot)org
Subject: [GENERAL] COPY column order

Hi there

I'm trying to use COPY with HEADER option but my header line in file is in
different order than the column order specified in database.
Is the column name order necessary in my file ??

thxs

--
View this message in context: http://postgresql.1045698.n5.nabble.com/COPY-column-order-tp5690950.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

--
Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
--
Please consider the environment before printing this email.
NIWA is the trading name of the National Institute of Water & Atmospheric Research Ltd.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Magnus Hagander 2012-05-07 19:27:28 Re: errors on restoring postgresql binary dump to glusterfs
Previous Message Scott Briggs 2012-05-07 19:10:59 Upgrading from 8.4 and 9.0 to 9.1