views:

197

answers:

2

Using Mysql Administrator GUI tool - I have exported some data tables retrieved from an sql dumpfile into csv files.

I then tried to import these csv files into a postgres database using the postgres COPY command. I've tried entering "COPY articles FROM '[insert .csv dir here]' DELIMITERS ',' CSV;" and also the same command without the delimiters part.

I get an error saying "ERROR:invalid input syntax for integer: "id"" and "CONTEXT: COPY articles, line 1, column id: "id"

In conclusion my question is what are some thoughts and solutions to this problem? Could it possibly be something to do with the way I created the csv files? or have I made a rookie mistake elsewhere?

A: 

i'm with thegeek. because you already tagged this as a python question, build a handfull-liner script to import this csv file. it's easy, i've made it yesterday because i had a similar problem and no patience with the copy-command of postgres ;)

Thomas Sittig
+2  A: 

If you have header columns just add the header qualifier to the copy statement as per documentation to skip that line http://www.postgresql.org/docs/8.4/static/sql-copy.html

Gavin
COPY articles FROM '[insert .csv dir here]' CSV WITH HEADER;
rfusca
Ah yeah awesome. Thanks so much this worked well. lol although it did produce a lot of unwanted white space in the data put into the table, but I guess thats a new problem I have to try and solve.
Oh disregard what I said about the post-problem encountered. I didnt realise that the data is actually squished and displays wierdly when viewing it in the terminal.