Skip to content
Advertisement

What is the syntax of array literal in H2 db?

I need to write an insert query where one value is an array of 3 elements. I’ve tried to do it like this:

  INSERT INTO some_table (id, col) VALUES (1, '{1, 2, 3}');

The sintax I’ve used for ‘col’ value is valid array literal in PostrgreSQL but H2 treats it as a single value of the array but not as an array with 3 elements.

Table DDL:

  CREATE TABLE some_table (
    id INT PRIMARY KEY ,
    col ARRAY
  );

Advertisement

Answer

Based on SQL Grammar:

enter image description here

INSERT INTO some_table (id, col) VALUES (1, (1, 2, 3))
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement