Giorgos Voukounas
Giorgos Voukounas

Reputation: 13

How to fix "invalid syntax for integer : 'NUM'

I have this CSV file and I want to copy it to the table I created but pgadmin outputs:

ERROR: invalid input syntax for integer: "NUM" CONTEXT: COPY tickets, line 1, column num: "NUM" SQL state: 22P02

The COPY code :

copy TICKETS(NUM,KIND,LOCATIONS,PRICE,DATES,CAT)
FROM 'C:\tmp\tickets.csv' DELIMITER ',' CSV

The CSV file:

enter image description here

Upvotes: 1

Views: 527

Answers (1)

James
James

Reputation: 3015

Why don't you try this way:

create table TICKETS(
  NUM INT,
  KIND INT,
  LOCATION VARCHAR(100),
  PRICE INT,
  DATE DATE,
  CAT CHAR(1)
)

LOAD DATA INFILE 'C:/tmp/tickets.csv' 
INTO TABLE TICKETS
FIELDS TERMINATED BY ',' 
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;

The important point is the last line IGNORE 1 ROWS excludes the titles, and no error raises.

Upvotes: 3

Related Questions