\copy command: how to define a tab character as the delimiter

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

\copy command: how to define a tab character as the delimiter

От:
Thomas Kellerer <spam_eater@gmx.net>
Дата:
Hi,

I tried to import a text file using the \copy command in psql using the following:

\copy foo (foo, bar) from foobar.txt delimiter as '\t' csv header

but that gives me an error:

ERROR:  COPY delimiter must be a single one-byte character

So how can I specify a tab character if I also need to specify that my file has a header line?

Regards
Thomas

Re: \copy command: how to define a tab character as the delimiter

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Thomas Kellerer  writes:
> \copy foo (foo, bar) from foobar.txt delimiter as '\t' csv header

> So how can I specify a tab character if I also need to specify that my file has a header line?

Type an actual tab.

			regards, tom lane

Re: \copy command: how to define a tab character as the delimiter

От:
Thomas Kellerer <spam_eater@gmx.net>
Дата:
Tom Lane wrote on 09.03.2010 18:21:
> Thomas Kellerer  writes:
>> \copy foo (foo, bar) from foobar.txt delimiter as '\t' csv header
>
>> So how can I specify a tab character if I also need to specify that my file has a header line?
>
> Type an actual tab.
>

Blush....

That easy?


Thanks
Thomas

Re: \copy command: how to define a tab character as the delimiter

От:
Raymond O'Donnell <rod@iol.ie>
Дата:
On 09/03/2010 17:30, Thomas Kellerer wrote:
> Tom Lane wrote on 09.03.2010 18:21:
>> Thomas Kellerer  writes:
>>> \copy foo (foo, bar) from foobar.txt delimiter as '\t' csv header
>>
>>> So how can I specify a tab character if I also need to specify that
>>> my file has a header line?
>>
>> Type an actual tab.
>>
> 
> Blush....
> 
> That easy?

This is Postgres you're talking about - of course it's that easy! :-)

Ray.

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

Re: \copy command: how to define a tab character as the delimiter

От:
Thomas Kellerer <spam_eater@gmx.net>
Дата:
Raymond O'Donnell wrote on 09.03.2010 18:39:
> This is Postgres you're talking about - of course it's that easy! :-)

:)

The main reason I asked, was that the manual actually claims that '\t' can be used ("The following special backslash sequences are recognized by COPY FROM")

As this is part of the description for the COPY command, does this maybe mean it is only valid for COPY but not for \copy?
if that is the case, it should be documented somewhere).

Or is this related to the value of standard_conforming_strings?

Thomas

Re: \copy command: how to define a tab character as the delimiter

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Thomas Kellerer  writes:
> The main reason I asked, was that the manual actually claims that '\t' can be used ("The following special backslash sequences are recognized by COPY FROM")

\t is recognized in the copy data, not in the command's parameters.

			regards, tom lane

Re: \copy command: how to define a tab character as the delimiter

От:
Adrian Klaver <adrian.klaver@gmail.com>
Дата:
On 03/09/2010 10:09 AM, Thomas Kellerer wrote:
> Raymond O'Donnell wrote on 09.03.2010 18:39:
>> This is Postgres you're talking about - of course it's that easy! :-)
>
> :)
>
> The main reason I asked, was that the manual actually claims that '\t'
> can be used ("The following special backslash sequences are recognized
> by COPY FROM")
>
> As this is part of the description for the COPY command, does this maybe
> mean it is only valid for COPY but not for \copy?
> if that is the case, it should be documented somewhere).
>
> Or is this related to the value of standard_conforming_strings?
>
> Thomas
>
>

 From here:
http://www.postgresql.org/docs/8.4/interactive/app-psql.html
"The syntax of the command is similar to that of the SQL COPY  command. 
Note that, because of this, special parsing rules apply to the \copy 
command. In particular, the variable substitution rules and backslash 
escapes do not apply. "

-- 
Adrian Klaver
adrian.klaver@gmail.com
FAQ