HSQL:创建索引(如果不存在) [英] HSQL: Creating index if not existing

查看:201
本文介绍了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
    

    这篇关于HSQL:创建索引(如果不存在)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆