加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql – 使用liquibase标签将最大列值设置为序列起始值

发布时间:2020-12-12 08:47:50 所属栏目:MsSql教程 来源:网络整理
导读:我不知道是否可以从某个表获取最大列值,并将其设置为没有纯sql的起始序列值.以下代码不起作用: property name="maxId" value="(select max(id)+1 from some_table)" dbms="h2,mysql,postgres"/ changeSet author="author (generated)" id="1447943899053-1"
我不知道是否可以从某个表获取最大列值,并将其设置为没有纯sql的起始序列值.以下代码不起作用:
<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"

我已经尝试了没有括号在选择…等等与相同的结果.
所以不可能使用计算值作为起始序列值?

解决方法

所以,这样的解决方案对我有用:
<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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读