Unfortunately, H2 does not treat (1) as array. The same problem occurs when casting an integer to array:
cast(1 as ARRAY) results in a single element array containing the String '1'. From: IanP <[email protected]> To: [email protected] Date: 2015-07-10 16:02 Subject: [h2] Bug in array datatype handling? Sent by: [email protected] 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 ARRAY_CONTAINS(ARRAYCOL, 1) ARRAY_CONTAINS(ARRAYCOL, '1') (1) FALSE TRUE (1 row, 3 ms) select arraycol, array_contains(arraycol, 1), array_contains(arraycol, '1') from arraytest where id = 2; ARRAYCOL ARRAY_CONTAINS(ARRAYCOL, 1) ARRAY_CONTAINS(ARRAYCOL, '1') (1) TRUE FALSE (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. ================================================================================================================ Disclaimer The information contained in this e - mail and any attachments ( together the "message") is intended for the addressee only and may contain confidential and/or privileged information. If you have received the message by mistake please delete it and notify the sender and do not copy or distribute it or disclose its contents to anyone. FINARIS Financial Software Partner GmbH, Sömmerringstr. 23, 60322 Frankfurt/Main, Germany Registered at Frankfurt/Main, HRB 52873, Managing Directors: Dipl. Inf. Hermann Friebel, Dipl. Ing. Kai Bächle, Dipl. Inf. Werner Märkl ================================================================================================================ -- 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.
