Postgresql - 使用带有改变序列表达式的子查询 [英] Postgresql - Using subqueries with alter sequence expressions
本文介绍了Postgresql - 使用带有改变序列表达式的子查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在 PostgreSQL 的 alter 表达式中使用子查询?
Is it possible to use subqueries within alter expressions in PostgreSQL?
我想根据主键列值更改序列值.
I want to alter a sequence value based on a primary key column value.
我尝试使用以下表达式,但它不会执行.
I tried using the following expression, but it wouldn't execute.
alter sequence public.sequenceX restart with (select max(table_id)+1 from table)
推荐答案
我不相信你可以那样做,但你应该能够使用alter所做的setval函数方向.
I don't believe you can do it like that but you should be able to use the setval function direction which is what the alter does.
select setval('sequenceX', (select max(table_id)+1 from table), false)
false 将使它返回给定的下一个序列号.
The false will make it return the next sequence number as exactly what is given.
这篇关于Postgresql - 使用带有改变序列表达式的子查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文