dbTalk Databases Forums  

Re: help with COPY query

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Re: help with COPY query in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Bruno LEVEQUE
 
Posts: n/a

Default Re: help with COPY query - 02-28-2004 , 05:54 PM






Hi,

I think the better is to modify you file before.
With sed it should be something like :

sed "s/\(\tab[0-9][0-9]*\).[0-9][0-9]*\(\tab\)/\1\2/" file > newfile

where \tab is the tabulation (or ctrl-V ctrl-I)

You can do the same with vi

vi file
:%s/\(\tab[0-9][0-9]*\).[0-9][0-9]*\(\tab\)/\1\2/
:wq

Bruno


On Tue, 24 Feb 2004, Elinor Medezinski wrote:

Quote:
Hi,
I want to load a file containning a column of FLOATS, into a table of
INTEGERs.

I tried:
COPY "Field" ("myintegers") from './myfloats.txt';
but got an error message:
ERROR: invalid input syntax for integer: "15.0"
CONTEXT: COPY Field, line 1, column WatchFreq: "15.0"
How can I go around this problem? is there any way to force copy to do the
right casting?

Thanks in advance,
Elinor

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


Bruno LEVEQUE
System Engineer
SARL NET6D
bruno.leveque (AT) net6d (DOT) com
http://www.net6d.com

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)



Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: help with COPY query - 02-28-2004 , 10:00 PM






Elinor Medezinski <elinor (AT) bellatrix (DOT) tau.ac.il> writes:
Quote:
I want to load a file containning a column of FLOATS, into a table of
INTEGERs.
...
How can I go around this problem? is there any way to force copy to do the
right casting?
COPY is not designed to do data manipulation for you. The best bet is
to load the data file into a temp table that has a column set matching
the data file, and then use INSERT ... SELECT to transform the data
and insert it into the final table.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.