Liquibase唯一约束的前提条件

时间:2013-01-14 19:17:11

标签: sql liquibase preconditions

我想使用Liquibase为列添加唯一约束。当然我想检查是否存在使用前置条件的重复行。

我想出了这个:

<preConditions>
    <sqlCheck expectedResult="0">
        select count(*)
        from person
        having ( count(username) > 1 )
    </sqlCheck>
</preConditions>

然而,这会在MySQL和其他数据库上产生Empty set

我尝试使用expectedResult=""expectedResult="null",但两者都不起作用。

1 个答案:

答案 0 :(得分:6)

你总是可以强制结果:

select 
  case when exists(
    select username, count(*)
    from person
    group by username
    having count(*) > 1 )
    then 1
    else 0
  end

这也允许更正常的群体/有

相关问题