From: | Patrick B Kelly <pbk(at)patrickbkelly(dot)org> |
---|---|
To: | Adam Witney <awitney(at)sghms(dot)ac(dot)uk> |
Cc: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Can COPY skip columns? |
Date: | 2004-11-18 21:08:04 |
Message-ID: | F006450C-39A5-11D9-B26C-000A958A3956@patrickbkelly.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Nov 18, 2004, at 11:53 AM, Adam Witney wrote:
>
> Hi,
>
> Is it possible for the COPY command to read data from a file, but skip
> specific columns?
>
You can use awk to skip fields and create an intermediate file or
better yet, just pipe the output to copy. Here is a trivial example:
awk '{ FS = "\t" ; OFS = "\t" ; print $1,$3 }' inputdatafile
This sets the input and output field separators to tab and outputs the
first and third fields from inputdatafile. If you want to skip the
first record just add the following if statement:
awk '{ FS = "\t" ; OFS = "\t" ; if ( NR > 1 ) print $1,$3 }'
inputdatafile
Patrick B. Kelly
------------------------------------------------------
http://patrickbkelly.org
From | Date | Subject | |
---|---|---|---|
Next Message | Rachel McConnell | 2004-11-18 21:11:01 | only seeing first of many COPY commands in input file |
Previous Message | Chris Browne | 2004-11-18 18:50:22 | Re: How to make a good documentation of a database ? |