Re: Can COPY skip columns? - Mailing list pgsql-general

From Patrick B Kelly
Subject Re: Can COPY skip columns?
Date
Msg-id F006450C-39A5-11D9-B26C-000A958A3956@patrickbkelly.org
Whole thread Raw
In response to Can COPY skip columns?  (Adam Witney <awitney@sghms.ac.uk>)
List 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


pgsql-general by date:

Previous
From: George Essig
Date:
Subject: Re: How to make a good documentation of a database ?
Next
From: Rachel McConnell
Date:
Subject: only seeing first of many COPY commands in input file