H2 database - CSVREAD - skip loading header line of the csv file into db

笑着哭i 提交于 2020-01-23 11:24:07

问题


I am using H2 DB in my java application. I want to load a .csv file to the DB. This file contains column headers as the first line of the file. So while loading the file into the DB through CSVREAD command, H2 is trying to parse the first line also and thus failing.

So how to skip loading the first line. Below the query I am using to load the file to the DB:

"CREATE TABLE TEST (CIRCLE VARCHAR_IGNORECASE(50), MSISDN VARCHAR_IGNORECASE(50), PORT_IN_DATE TIMESTAMP, OPERATOR VARCHAR_IGNORECASE(255), PRODUCT_TYPE VARCHAR_IGNORECASE(255), PORT_ID VARCHAR_IGNORECASE(255)) AS SELECT * FROM CSVREAD('src/test/resources/test.csv', "

回答1:


The CSVREAD function supports both files with and without column header. If the file contains a column header, then don't supply the column list in the function, for example:

SELECT * FROM CSVREAD('test.csv');
SELECT * FROM CSVREAD('data/test.tsv', null, 'rowSeparator=' || CHAR(9));

and if the file doesn't contains the column header, then supply the column list in the function call, for example:

SELECT * FROM CSVREAD('test2.csv', 'ID|NAME', 'charset=UTF-8 fieldSeparator=|');


来源:https://stackoverflow.com/questions/8761690/h2-database-csvread-skip-loading-header-line-of-the-csv-file-into-db

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!