Hi,

I think I see a bug in array datatype handling. Specifically an array is 
handled as string[] or an int[] depending on a trailing ',' char. I found 
it while fixing what looked like a bug in my code that was issuing commands 
like 

INSERT INTO TABLENAME VALUES(1, (1,))

and then discovered my fix caused a regression. It can be can recreated 
like this...

drop table if exists arraytest;
Update count: 0
(0 ms)

create table arraytest(id int, arraycol array);
Update count: 0
(1 ms)

insert into arraytest values(1, (1));
Update count: 1
(0 ms)

insert into arraytest values(2, (1,));
Update count: 1
(0 ms)

select arraycol, array_contains(arraycol, 1), array_contains(arraycol, '1') 
from arraytest where id = 1;
ARRAYCOL   
<http://192.168.0.5:8082/query.do?jsessionid=ca6be2702202f4ba3ebe2dec7f6de719#>ARRAY_CONTAINS(ARRAYCOL,
 
1)   
<http://192.168.0.5:8082/query.do?jsessionid=ca6be2702202f4ba3ebe2dec7f6de719#>ARRAY_CONTAINS(ARRAYCOL,
 
'1')   
<http://192.168.0.5:8082/query.do?jsessionid=ca6be2702202f4ba3ebe2dec7f6de719#>
(1)FALSETRUE(1 row, 3 ms)

select arraycol, array_contains(arraycol, 1), array_contains(arraycol, '1') 
from arraytest where id = 2;
ARRAYCOL   
<http://192.168.0.5:8082/query.do?jsessionid=ca6be2702202f4ba3ebe2dec7f6de719#>ARRAY_CONTAINS(ARRAYCOL,
 
1)   
<http://192.168.0.5:8082/query.do?jsessionid=ca6be2702202f4ba3ebe2dec7f6de719#>ARRAY_CONTAINS(ARRAYCOL,
 
'1')   
<http://192.168.0.5:8082/query.do?jsessionid=ca6be2702202f4ba3ebe2dec7f6de719#>
(1)TRUEFALSE(1 row, 0 ms)

Note that on the two rows the array_contains functions match differently 
against int and string types. The only difference in the row inserts is the 
trailing comma on the array value. I guess it should be treating them as 
ints if they are unquoted, and only as strings if they are quoted like this:

insert into arraytest values(1, (1)); // Should be int
insert into arraytest values(1, ('1')); // Should be string

A bug, or is it some subtlety about arrays that I have missed?

Cheers,
Ian.

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to