Re: loading delimited files

From: will trillich <will(at)serensoft(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: loading delimited files
Date: 2003-01-21 18:28:59
Message-ID: 20030121182859.GB4849@mail.serensoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Jan 13, 2003 at 01:27:29PM -0500, Campano, Troy wrote:
> Are there docs on how to load delimited files into the database?

closer than you might think. "\h copy"!

psql somedatabase

somedatabase> \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' ]

\t (tab) is default field separator,
\n (newline) is default record separator,
\N is default for NULL

pick a small table in your current database and try

psql> copy tinytable to stdout;

to see the format. note that ALL fields in the table are
exported, and should be included on the import, as well (in
field-definition order, from your create statements).

psql> copy atable FROM '/this/file/here.tsv';

--
There are 10 kinds of people:
ones that get binary, and ones that don't.

will(at)serensoft(dot)com
http://sourceforge.net/projects/newbiedoc -- we need your brain!
http://www.dontUthink.com/ -- your brain needs us!

Looking for a firewall? Do you think smoothwall sucks? You're
probably right... Try the folks at http://clarkconnect.org/ !

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2003-01-21 18:48:50 Re: PL/Python
Previous Message Tom Jenkins 2003-01-21 18:25:52 Re: PL/Python