LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Postgresql 8.47.on Debian/ Gnu Squeeze-stable. Imporitng data (https://www.linuxquestions.org/questions/linux-software-2/postgresql-8-47-on-debian-gnu-squeeze-stable-imporitng-data-875209/)

Learnix 04-15-2011 12:14 PM

Postgresql 8.47.on Debian/ Gnu Squeeze-stable. Imporitng data
 
Hi,
I imported one table from a csv file format with no problems.
The file fields where matching my table fields.

*** For a second table import (I will use a similar example to simplify:

--- So I created a table with the following fields:

Contactname addr city zipcode

the file to import has the following fields

Contactname firstname middlename lastname addr city zipcode.

Is there a way to import the file by listing the columns
I tried :
copy MyTableName column(contactname,,,,addr,city,zipcode) from 'pathtomycsvfile' with null as '' csv header quote as '"' escape as '"' ;
The error is always pointing to the 'c' of column I tried to remove the parenthesis I removed the statement 'column' and other scenarios
It Didn't work.
Does that mean that I will absolutely have to remove those unwanted columns from the import file. I have about 120 of those files to import.
If I can avoid to do the later what would be the right statement.

Cheers,

Tinkster 04-15-2011 07:05 PM

There are two problems here:

a) You're using a column keyword that doesn't exist; what you'd want
to do normally is:
Code:

copy MyTableName (contactname,addr,city,zipcode) from 'pathtomycsvfile' with null as '' csv header quote as '"' escape as '"' ;
b) You can't import parts of a csv; every column in the CSV must
be matched in your table structure. Look at PGLoader, or sanitise
your data ...


Cheers,
Tink


All times are GMT -5. The time now is 11:56 PM.