本文介绍了使用liquibase标签将最大列值设置为序列起始值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我想知道是否有可能从某个表中获取最大列值并将其设置为没有纯sql的开始序列值.以下代码不起作用:

I wonder if it possible to get maximum column value from a certain table and set it as start sequence value with no pure sql. The following code doesn't work:

   <property name="maxId" value="(select max(id)+1 from some_table)" dbms="h2,mysql,postgres"/>
   <changeSet author="author (generated)" id="1447943899053-1">
      <createSequence sequenceName="id_seq" startValue="${maxId}" incrementBy="1"/>
   </changeSet>

出现错误:

Caused by: liquibase.parser.core.ParsedNodeException: java.lang.NumberFormatException: For input string: "${m"

我尝试过在select ...等处没有括号的情况,但结果相同.因此,不可能将计算值用作起始序列值吗?

I've tried it with no parentheses around select ... etc. with the same result.So it's not possible to use computed value as start sequence value?

推荐答案

因此,这样的解决方案对我有用:

So, such a solution worked for me:

<changeSet author="dfche" id="1448634241199-1">
  <createSequence sequenceName="user_id_seq" startValue="1" incrementBy="1"/>
</changeSet>
<changeSet author="dfche" id="1448634241199-2">
  <sql dbms="postgresql">select setval('user_id_seq', max(id)+1) from jhi_user</sql>
  <sql dbms="h2">alter sequence user_id_seq restart with (select max(id)+1 from jhi_user)</sql>
</changeSet>

这篇关于使用liquibase标签将最大列值设置为序列起始值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 19:44