我想知道是否有可能从某个表中获取最大列值并将其设置为没有纯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"
我试过了,没有括号select ...等,结果也一样。因此,不可能将计算值用作起始序列值吗?
select ...
因此,这样的解决方案对我有用:
<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>