Re: Can COPY skip columns?

Поиск
Список
Период
Сортировка
От Patrick B Kelly
Тема Re: Can COPY skip columns?
Дата
Msg-id F006450C-39A5-11D9-B26C-000A958A3956@patrickbkelly.org
обсуждение исходный текст
Ответ на Can COPY skip columns?  (Adam Witney <awitney@sghms.ac.uk>)
Список 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 по дате отправления:

Предыдущее
От: George Essig
Дата:
Сообщение: Re: How to make a good documentation of a database ?
Следующее
От: Rachel McConnell
Дата:
Сообщение: only seeing first of many COPY commands in input file