Liquibase唯一约束的前提条件

sie*_*z0r 3 sql liquibase preconditions

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

我想出来了:

<preConditions>
    <sqlCheck expectedResult="0">
        select count(*)
        from person
        having ( count(username) > 1 )
    </sqlCheck>
</preConditions>
Run Code Online (Sandbox Code Playgroud)

然而,这产生Empty set于MySQL和其他数据库.

我试着用expectedResult=""expectedResult="null",但都不起作用.

Boh*_*ian 6

你总是可以强制结果:

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

这也允许更普通的群体/拥有