Load Text File into DB

Started by Karl J. Stubsjoenalmost 25 years ago4 messagesgeneral
Jump to latest
#1Karl J. Stubsjoen
karlflips@kstub.com

Hello,

I have a tab delimited text file located on the server and would like to
load this into a table. How do I accomplish this?

Thanks!

Karl

#2Chris Jones
chris.jones@romancompany.com
In reply to: Karl J. Stubsjoen (#1)
Re: Load Text File into DB

This is what I have used with success..

copy {table name} from '{delimited file name}' using delimiters '\t' with
null as '';

Of course, don't put in the brackets and you can use whatever null character
you might need...

Hope this helps

Chris
Karl J. Stubsjoen wrote in message <9b20s1$1b3d$1@news.tht.net>...

Show quoted text

Hello,

I have a tab delimited text file located on the server and would like to
load this into a table. How do I accomplish this?

Thanks!

Karl

#3larry a price
laprice@efn.org
In reply to: Karl J. Stubsjoen (#1)
Re: Load Text File into DB

COPY tablename FROM '/home/path/filename';

with the table created with proper columns

Larry Price | "We have seen the truth.
laprice@efn.org | And the truth makes no sense." -chesterton
_______________________________________________________________

On Wed, 11 Apr 2001, Karl J. Stubsjoen wrote:

Show quoted text

Hello,

I have a tab delimited text file located on the server and would like to
load this into a table. How do I accomplish this?

Thanks!

Karl

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html

#4Jeff Eckermann
jeckermann@verio.net
In reply to: larry a price (#3)
RE: Re: Load Text File into DB

COPY expects tab delimiters by default, so specifying them is not strictly
necessary in this case.
Specifying "null as xxx" is a good idea, because COPY interprets an empty
field as an empty string, which will cause failure for non text-type fields.
A couple of other things to watch out for when bulk-loading data with COPY
(based on my painful experiences):
* Embedded delimiters, i.e. tabs in your data. Start by grepping for
lines with more than the expected number of tabs.
* Fields ending with a backslash. Sounds unlikely, but this has
happened to me several times. The result is that your delimiter is escaped,
shifting all of your following fields down by one. This will either cause
COPY to fail (because of data type mismatches), or messed up data in that
record.
* For files imported from a Windows machine, better edit out the
carriage returns.

Show quoted text

-----Original Message-----
From: Chris Jones [SMTP:chris.jones@romancompany.com]
Sent: Friday, April 13, 2001 1:27 PM
To: pgsql-general@postgresql.org
Subject: [GENERAL] Re: Load Text File into DB

This is what I have used with success..

copy {table name} from '{delimited file name}' using delimiters '\t' with
null as '';

Of course, don't put in the brackets and you can use whatever null
character
you might need...

Hope this helps

Chris
Karl J. Stubsjoen wrote in message <9b20s1$1b3d$1@news.tht.net>...

Hello,

I have a tab delimited text file located on the server and would like to
load this into a table. How do I accomplish this?

Thanks!

Karl

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly