Import csv

Started by Patrick Nelsonover 23 years ago3 messagesgeneral
Jump to latest
#1Patrick Nelson
pnelson@neatech.com

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.

#2Terry Fielder
terry@greatgulfhomes.com
In reply to: Patrick Nelson (#1)
Re: Import csv

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

Show quoted text

-----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)

#3Patrick Nelson
pnelson@neatech.com
In reply to: Terry Fielder (#2)
Re: Import csv

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!