Load Text File into DB
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
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
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?
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 DBThis 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
Import Notes
Resolved by subject fallback