RiberaHugo
RiberaHugo

Reputation: 27

import csv file in h2 database in several column

In my CSV file there is:

prenom; nom; age
prenom1; nom1; age1
prenom2; nom2; age2
...

When I import my CSV file using this command:

CREATE TABLE TEST AS SELECT * FROM CSVREAD('C:\Users\anonymous\Desktop\test.csv');

The main problem is that my database has 1 column with my CSV file..

I would like 3 columsn with prenom, nom and age with the data in each column.

Thanks for your help!

Upvotes: 0

Views: 2973

Answers (1)

Stavr00
Stavr00

Reputation: 3314

As @jdv stated, you must specify the field separator if it is not the default ,. The null specifies that the column names will be parsed from the first row.

CREATE TABLE TEST AS SELECT * FROM CSVREAD('C:\Users\anonymous\Desktop\test.csv',null,'fieldSeparator=;');

Keep in mind you may have to specify charset=Cp1252 as well, if the CSV file was generated with Excel. If you see something like prénom you have the wrong encoding.

Upvotes: 3

Related Questions