user2051347
user2051347

Reputation: 1669

Importing a csv file into postgresql

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?

Upvotes: 2

Views: 3168

Answers (1)

yieldsfalsehood
yieldsfalsehood

Reputation: 3085

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;

Upvotes: 4

Related Questions