NEWBIE: How do I use \copy to populate from a flat file

Started by Brian Burton-Cundallabout 27 years ago4 messagesgeneral
Jump to latest
#1Brian Burton-Cundall
lists@graith.co.uk

I've used mSQL before and managed to import flat files exported from MS Access
(needs must) into that. I need to import flat files into PostGreSQL. I've
created the table using psql - POSTGRESQL interactive sql monitor:

I can see the command from the help
\copy table {from | to} <fname>

I've got a flat file with TAB separated values that match the table but when I
use
\copy ENTRY from /u1/www/intranet/brian/ENTRY.txt

I get
Broken Pipe

and it returns to the shell prompt. Any ideas?

(I don't want to have to create 20,000+ INSERT SQL commands or even automate
it)

Thanks
Brian
Graith Internet - http://www.graith.co.uk

#2Michael A. Koerber
mak@ll.mit.edu
In reply to: Brian Burton-Cundall (#1)
Re: [GENERAL] NEWBIE: How do I use \copy to populate from a flat file

try adding "tics" and see if it works

\copy ENTRY from '/u1/www/intranet/brian/ENTRY.txt'

#3K.T.
kanet@calmarconsulting.com
In reply to: Michael A. Koerber (#2)
Re: [GENERAL] NEWBIE: How do I use \copy to populate from a flat file

I also think the ticks that Michael is talking about are required. You can
usually find more information about the "copy" error in the server.log
(don't know where this is located on your system).

-----Original Message-----
From: Brian Burton-Cundall <lists@graith.co.uk>
To: pgsql-general@postgreSQL.org <pgsql-general@postgreSQL.org>
Date: Tuesday, March 02, 1999 6:09 AM
Subject: [GENERAL] NEWBIE: How do I use \copy to populate from a flat file

I've used mSQL before and managed to import flat files exported from MS

Access

(needs must) into that. I need to import flat files into PostGreSQL. I've
created the table using psql - POSTGRESQL interactive sql monitor:

I can see the command from the help
\copy table {from | to} <fname>

I've got a flat file with TAB separated values that match the table but

when I

use
\copy ENTRY from /u1/www/intranet/brian/ENTRY.txt

I get
Broken Pipe

and it returns to the shell prompt. Any ideas?

(I don't want to have to create 20,000+ INSERT SQL commands or even

automate

Show quoted text

it)

Thanks
Brian
Graith Internet - http://www.graith.co.uk

#4Gene Selkov, Jr.
selkovjr@mcs.anl.gov
In reply to: K.T. (#3)
Re: [GENERAL] NEWBIE: How do I use \copy to populate from a flat file

I also think the ticks that Michael is talking about are required. You can
usually find more information about the "copy" error in the server.log
(don't know where this is located on your system).

The file name must be enclosed in single closing quotes ('\047'). And
by the way, psql (if built with readline library) allows emacs-style
command line editing and can complete file names like bash does (I am
also wondering if it's possible to improve it to complete SGL keywords
and table names). I always use completion to make sure the file exists
and is accessible:

copy ENTRY from '/u1
<TAB>w
copy ENTRY from '/u1/w
<TAB>
copy ENTRY from '/u1/www/
<TAB><TAB> to see choices
....

';<CR>

BTW, what did you mean by '\copy'?

--Gene