Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using curly bracket in H2 table name

Tags:

h2

My application uses MySQL database and it has table utils.'{UserUtils}'. I need to write a test that would use the same queries, but with the H2 database for tests. But I can't create such a table in H2, I have error:

Syntax error in SQL statement 
  "create table utils.`{UserUtils}`[*]" [42000-196]

Is it possible to somehow tell H2 to create such a table or are the names strictly limited?

like image 848
All_Safe Avatar asked Dec 01 '25 01:12

All_Safe


1 Answers

In MySQL, you need to enclose identifiers with special characters using back quotes (`). However, in H2 the correct way of using identifiers with special characters is to enclose them in double quotes ("). I just tried in H2 v1.4 without any trouble:

create table "{UserUtils}" (
  id int
);

insert into "{UserUtils}" (id) values (123);
insert into "{UserUtils}" (id) values (456);

select * from "{UserUtils}";

Returns:

ID           
-------------
123          
456          

Maybe you are using an older/newer version of H2.

like image 82
The Impaler Avatar answered Dec 04 '25 06:12

The Impaler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!