HSQL:创建索引(如果不存在)
我正在使用Spring通过
I'm initializing a HSQL database 2.2.9 via Spring using
<jdbc:initialize-database enabled="true">
<jdbc:script execution="INIT" location="classpath:./create-tables.sql"/>
</jdbc:initialize-database>
在create-tables.sql
我使用
CREATE TABLE IF NOT EXISTS MyTable(...);
该表还具有索引.我正在寻找比总是删除和创建索引更好的方法.
The table also has an index. I'm looking for a better way than always dropping and creating the index.
我尝试过:
CREATE INDEX IF NOT EXISTS myIndex ...;
- 不起作用
我可以创建一个函数indexExisting()
,如果找到索引,但是如果我写的话,将检查系统表并返回count(*)> 0
I can create a function indexExisting()
checking the system tables and returning count(*) > 0 if the index is found, but if I write
IF indexExisting() = 0 THEN ...
直接进入.sql
文件,
java.sql.SQLSyntaxErrorException: unexcepted token: IF
据我所知,存储过程似乎也无济于事,因为它们可能不包含DROP语句.
Also a stored procedure does not seem to help, as they may not contain DROP statements, as far as I read.
因此,除了删除/创建索引以外的解决方案也将受到欢迎.
So a solution other than dropping / creating the index would be appreciated.
谢谢
最新版本的HSQLDB支持以下两者:
The latest version of HSQLDB supports both:
CREATE INDEX IF NOT EXISTS myIndex ...
DROP INDEX IF EXISTS myIndex