Strange delimiters problem

Started by Andrej Kastrinalmost 19 years ago4 messagesgeneral
Jump to latest
#1Andrej Kastrin
andrej.kastrin@siol.net

Dear all,

I am experiencing difficulty in trying to copy the file structure below
into PostgreSQL table:

||001||,||Classification||,||Economics||,||N||
||001||,||Classification||,||Trends||,||Y||
etc...

Although I can preprocess the input file with e.g awk, I would like to
know is it possible to do that directly in PostgreSQL.

Thanks in advance for any suggestions.

Best, Andrej

In reply to: Andrej Kastrin (#1)
Re: Strange delimiters problem

On 6/3/07, Andrej Kastrin <andrej.kastrin@siol.net> wrote:

||001||,||Classification||,||Economics||,||N||
||001||,||Classification||,||Trends||,||Y||
etc...

it looks like you should be able to read it using COPY command.
something like:
copy some_table from stdin with delimiter ',' csv quote '||';

depesz

#3Andrej Kastrin
andrej.kastrin@siol.net
In reply to: hubert depesz lubaczewski (#2)
Re: Strange delimiters problem

hubert depesz lubaczewski wrote:

On 6/3/07, *Andrej Kastrin* <andrej.kastrin@siol.net
<mailto:andrej.kastrin@siol.net>> wrote:

||001||,||Classification||,||Economics||,||N||
||001||,||Classification||,||Trends||,||Y||
etc...

it looks like you should be able to read it using COPY command.
something like:
copy some_table from stdin with delimiter ',' csv quote '||';

depesz

Thanks,
but I receive the following error message when I'm trying to run the
proposed copy command:

ERROR: COPY quote must be a single character

I use PostgreSQL 8.1.5.

Best, Andrej

#4Andrej Ricnik-Bay
andrej.groups@gmail.com
In reply to: Andrej Kastrin (#1)
Re: Strange delimiters problem

On 6/3/07, Andrej Kastrin <andrej.kastrin@siol.net> wrote:

I am experiencing difficulty in trying to copy the file structure below
into PostgreSQL table:

||001||,||Classification||,||Economics||,||N||
||001||,||Classification||,||Trends||,||Y||
etc...

Although I can preprocess the input file with e.g awk, I would like to
know is it possible to do that directly in PostgreSQL.

Thanks in advance for any suggestions.

I think you might be able to. You can have CSV with your pipes
(as QUOTE in [ CSV [ HEADER ] [ QUOTE [ AS ] 'quote' ] )

http://www.postgresql.org/docs/8.2/static/sql-copy.html

Best, Andrej

Cheers,
Andrej