我想知道是否有可能从某个表格中获取最大列值,并将其设置为起始序列值,而无需使用纯 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 ...
等周围加上括号,结果相同。所以无法将计算值用作起始序列值?
<sql>
标签运行select setval('id_seq', (select max(id)+1 from some_table));
。 - user330315
alter sequence user_id_seq restart with 333
alter sequence user_id_seq restart with (select max(id)+1 from jhi_user)
H2可以正常工作。对于Postgres,“select setval(...)”不起作用,也不会“alter sequence ... restart with ...”。 - dfche<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>
- dfche