Thread: Import csv

Import csv

From
Patrick Nelson
Date:
I'm away from my PostgreSQL book (me SQL bible) and I'm faced with importing
csv (comma separated vales) file where I had setup all my scripts to tsv
(tab separated vales).  Yes I can use an editor, as such and change the
commas, but that's not the question.

How do I take a basic csv file and insert it into my table (named
dwnldstockanal)?  Just feel that this is something that I should know, but
me scratches me head.

Re: Import csv

From
terry@greatgulfhomes.com
Date:
devtest2=# \h copy
Command:     COPY
Description: copy data between files and tables
Syntax:
COPY [ BINARY ] table [ WITH OIDS ]
    FROM { 'filename' | stdin }
    [ [USING] DELIMITERS 'delimiter' ]
    [ WITH NULL AS 'null string' ]
COPY [ BINARY ] table [ WITH OIDS ]
    TO { 'filename' | stdout }
    [ [USING] DELIMITERS 'delimiter' ]
    [ WITH NULL AS 'null string' ]

Hence

COPY t1 FROM '<filename>' USING DELIMITERS ',';

Terry Fielder
Network Engineer
Great Gulf Homes / Ashton Woods Homes
terry@greatgulfhomes.com

> -----Original Message-----
> From: pgsql-general-owner@postgresql.org
> [mailto:pgsql-general-owner@postgresql.org]On Behalf Of Patrick Nelson
> Sent: Friday, July 26, 2002 1:45 PM
> To: PostgreSQL List (E-mail)
> Subject: [GENERAL] Import csv
>
>
> I'm away from my PostgreSQL book (me SQL bible) and I'm faced
> with importing
> csv (comma separated vales) file where I had setup all my
> scripts to tsv
> (tab separated vales).  Yes I can use an editor, as such and
> change the
> commas, but that's not the question.
>
> How do I take a basic csv file and insert it into my table (named
> dwnldstockanal)?  Just feel that this is something that I
> should know, but
> me scratches me head.
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to
> majordomo@postgresql.org)
>

Re: Import csv

From
Patrick Nelson
Date:
terry@greatgulfhomes.com wrote:
----------------->>>>
devtest2=# \h copy
Command:     COPY
Description: copy data between files and tables
Syntax:
COPY [ BINARY ] table [ WITH OIDS ]
    FROM { 'filename' | stdin }
    [ [USING] DELIMITERS 'delimiter' ]
    [ WITH NULL AS 'null string' ]
COPY [ BINARY ] table [ WITH OIDS ]
    TO { 'filename' | stdout }
    [ [USING] DELIMITERS 'delimiter' ]
    [ WITH NULL AS 'null string' ]

Hence

COPY t1 FROM '<filename>' USING DELIMITERS ',';
----------------->>>>

Didn't even think of the psql \h copy... DOH!  Feel like a tard!  Anyway
thanks!