load or import csv file into table?

2,463 views
Skip to first unread message

joe

unread,
May 28, 2010, 5:49:24 AM5/28/10
to H2 Database
Any easy way I can programmatically load a CSV file into an in-memory
H2 table? Something comparable to Oracle's SQL loader, or IBM db2load?

Thomas Mueller

unread,
May 28, 2010, 12:50:20 PM5/28/10
to h2-da...@googlegroups.com
Hi,

I will add the following documentation at
http://h2database.com/html/tutorial.html#csv :

------------------------------------------------------

= Importing Data from a CSV File =

A fast way to load or import data (sometimes called 'bulk load') from
a CSV file is to combine table creation with import. Optionally, the
column names and data types can be set when creating the table.
Another option is to use INSERT INTO ... SELECT.

CREATE TABLE TEST AS SELECT * FROM CSVREAD('test.csv');
CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))
AS SELECT * FROM CSVREAD('test.csv');

------------------------------------------------------

Does this solve your problem?

Regards,
Thomas

Neil Mancini

unread,
Oct 25, 2013, 11:17:52 PM10/25/13
to h2-da...@googlegroups.com
where should the 'test.csv' be stored ?

Thomas Mueller

unread,
Nov 1, 2013, 12:33:27 PM11/1/13
to H2 Google Group
Hi,

where should the 'test.csv' be stored ?

This is the same as for "java.io.File". If you use CSVREAD('test.csv'), then the file needs to be in the current working directory. But of course you can use an absolute path.

Regards,
Thomas


--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to h2-database...@googlegroups.com.

To post to this group, send email to h2-da...@googlegroups.com.
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages