CSVREAD looses column (1.4.196)

75 views
Skip to first unread message

George Ivanov

unread,
Aug 8, 2019, 5:34:32 AM8/8/19
to H2 Database
Hello!

I am trying to create a table using the following CSV file (test.csv):
===
,,
0,1,2
===

CREATE TABLE A AS SELECT * FROM CSVREAD('test.csv');
SELECT * FROM A

However, in the result I see that the third column (COLUMN2) gets lost:

CSVREAD.png

Could you please check?

Thank you,
George

Evgenij Ryazanov

unread,
Aug 8, 2019, 8:41:55 AM8/8/19
to H2 Database
Hello.

Yes, it looks like a bug. You can use some non-empty name of the last column as a workaround.

A,B,C
0, 1, 2

Noel Grandin

unread,
Aug 8, 2019, 10:16:47 AM8/8/19
to h2-da...@googlegroups.com
possibly we just need an error message when the number of columns in the first line does not match the number of columns
in the data rows

Evgenij Ryazanov

unread,
Aug 8, 2019, 10:26:58 AM8/8/19
to H2 Database
Both lines have 3 columns, it's just a bug in Csv.readHeader() / Csv.readValue().

George Ivanov

unread,
Aug 8, 2019, 12:01:48 PM8/8/19
to H2 Database
I cannot use empty name, the empty value comes from Confluence page table where the header cell is empty

George Ivanov

unread,
Aug 8, 2019, 12:46:00 PM8/8/19
to H2 Database
Is the same bug present in the latest H2 release?

George Ivanov

unread,
Aug 8, 2019, 12:50:05 PM8/8/19
to H2 Database
Sorry, I meant, I cannot replace the empty name, since it is empty in the Confluence table that is used as the data source in this case, and I am not necessarily the owner of this table.


On Thursday, August 8, 2019 at 7:01:48 PM UTC+3, George Ivanov wrote:

George Ivanov

unread,
Sep 18, 2019, 5:55:02 AM9/18/19
to H2 Database
Hi Evgenij,

could you confirm which version of H2 will have this bug fixed, please?

Thank you!
George

Evgenij Ryazanov

unread,
Sep 18, 2019, 6:58:29 AM9/18/19
to H2 Database
Sorry, it isn't fixed yet.

Of course, you may submit a pull request with a fix if you wish. The relevant code is in org.h2.tools.Csv.

George Ivanov

unread,
Sep 18, 2019, 11:44:21 AM9/18/19
to H2 Database
OK, the problem is that when readValue() does:
        while (true) {
            int ch = readChar();

it gets first ch == fieldSeparatorRead ...

I think, the right way of fixing would be somehow escaping "empty" values with "" before that point. 
So, that when you read buffer, it would read 
,
as
"",""
However, I still have no clue how to achieve this within H2 code.

George Ivanov

unread,
Feb 5, 2020, 3:40:18 AM2/5/20
to H2 Database
hi Evgenij,

could you help with fixing this?

Evgenij Ryazanov

unread,
Feb 5, 2020, 11:01:45 AM2/5/20
to H2 Database
Hello.

CSVREAD needs many other changes and I don't have time for them right now.
Reply all
Reply to author
Forward
0 new messages