2

I have a *.csv file which I want to import into my database. basically it looks like that:

2013.11.07,11:50,1.35163,1.35167,1.35161,1.35163,15
2013.11.07,11:51,1.35166,1.35173,1.35165,1.35170,21
2013.11.07,11:52,1.35170,1.35170,1.35163,1.35163,11

I am using:

DROP TABLE table;

CREATE TABLE table
(
id SERIAL primary key,
Date Date,
Time Time,
Open double precision, 
High double precision, 
Low double precision,
Close double precision,
Volume bigint
);

COPY table FROM 'C:\\Users\\user\\EURUSD1.txt' DELIMITER ',' CSV;

However I am getting at the Date:

ERROR: invalid input syntax for integer: "07/11/2013" CONTEXT: COPY eurusd_m1, line 1, column id: "07/11/2013"

I really appreciate your help on how to fix that?

3
  • File format and Table Column order do not match neither do the number of columns. You need to create a table just like the data you want to load. Commented Jan 17, 2014 at 18:52
  • @Abhinav Thx for your answer! However, thats not correct! Number of columns of the create statement matches the csv(id is SERIAL). If I am wrong please show me! Commented Jan 17, 2014 at 18:55
  • 1
    Looking at the error it doesn't seem to be the case. Error says the COPY command is trying to assign Date data to id column. Commented Jan 17, 2014 at 18:59

1 Answer 1

4

Just because id is serial doesn't mean it's disregarded when loading - you should be specifying your columns in your copy statement, e.g.

COPY table (Date, Time, Open, High, Low, Close, Volume)
  FROM 'C:\\Users\\user\\EURUSD1.txt' DELIMITER ',' CSV;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.