With H2 Database can I perform a SQL query on CSV text read from a Java Reader e.g. StringReader?

You could write a user defined function that returns a result set, and use that to generate the required rows. Within your user defined function, you can use the Csv tool from H2 (actually any Csv tool).

Ah - I see what you mean. So maybe it might be a useful feature to add to the H2 Database: to include a built-in function CSVREAD(String csvcontent) ... like CSVREAD(filename), but instead of passing in the name of the CSV file, you pass in a string containing the actual CSV content. Of course this would only be useful if the CSV data is relatively small.

– nicciglen Nov 15 '11 at 13:44.

This is not possible directly, since DBMS can usually only query their own optimized data storage. You have to import the text with the mentioned org. H2.tools.Csv.

Read into a table and perform the queries on that table. The table may be a temporary one, to prevent any writes on the disk, assuming the memory is sufficient.

Yes, I understand what you mean, but so far I haven't been able to find an H2 Database Java API call to directly create a new table (temporary one) directly from the resultset returned by org. H2.tools.Csv. Read(...).

Otherwise, I have to cycle through each row in the resultset (in Java) and insert each row into a newly created temporary table (quite long winded). However, please let me know if there is indeed such a Java API call (to directly create a table from a resultset). – nicciglen Nov 16 '11 at 12:56.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions