Copying entire tsv record (from file) into a single field

Поиск
Список
Период
Сортировка
Искать

Copying entire tsv record (from file) into a single field

От:
Allan Kamau <kamauallan@gmail.com>
Дата:
I would like to use copy to populate a single row in table with data
from a tsv file for further transformations.
I seem not find a way to stop copy from seeing that the tsv file does
indeed contain fields.
This my current query

		COPY raw_data
		(
		raw_record
		)
		FROM
		'/tmp/some.tsv'
		;

Allan.

Re: Copying entire tsv record (from file) into a single field

От:
Raymond O'Donnell <rod@iol.ie>
Дата:
On 07/12/2010 11:07, Allan Kamau wrote:
> I would like to use copy to populate a single row in table with data
> from a tsv file for further transformations.
> I seem not find a way to stop copy from seeing that the tsv file does
> indeed contain fields.
> This my current query
>
> 		COPY raw_data
> 		(
> 		raw_record
> 		)
> 		FROM
> 		'/tmp/some.tsv'
> 		;

You can specify the character which COPY sees as the field delimiter to 
be something other than a tab - maybe a comma, if there are no commas in 
your input:

   copy raw_data(raw_record)
   from '/tmp/some.tsv'
   with delimiter ',';

Would that do the job?

Ray.

-- 
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie

Re: Copying entire tsv record (from file) into a single field

От:
Allan Kamau <kamauallan@gmail.com>
Дата:
On Tue, Dec 7, 2010 at 2:14 PM, Raymond O'Donnell  wrote:
> On 07/12/2010 11:07, Allan Kamau wrote:
>>
>> I would like to use copy to populate a single row in table with data
>> from a tsv file for further transformations.
>> I seem not find a way to stop copy from seeing that the tsv file does
>> indeed contain fields.
>> This my current query
>>
>>                COPY raw_data
>>                (
>>                raw_record
>>                )
>>                FROM
>>                '/tmp/some.tsv'
>>                ;
>
> You can specify the character which COPY sees as the field delimiter to be
> something other than a tab - maybe a comma, if there are no commas in your
> input:
>
>  copy raw_data(raw_record)
>  from '/tmp/some.tsv'
>  with delimiter ',';
>
> Would that do the job?
>
> Ray.
>
> --
> Raymond O'Donnell :: Galway :: Ireland
> rod@iol.ie
>

There are commas in the input, and there is no guarantee that any one
single character will not appear in the input. I could appoint a
character such as the comma as suggested then use sed to change all
commas in the incoming data to maybe '|' (pipe character) but this it
may change the semantics of the data if the incoming data does contain
pipe characters delimiting comma separated lists of values all in a
given logical field.

Allan.
FAQ