在postgres中重置自动增量计数器 [英] Reset auto increment counter in postgres
问题描述
我想将表的自动递增字段强制设置为某个值,我对此进行了尝试:
I would like to force the auto increment field of a table to some value, I tried with this:
ALTER TABLE product AUTO_INCREMENT = 1453
AND
ALTER SEQUENCE product RESTART WITH 1453;
ERROR: relation "your_sequence_name" does not exist
我是postgres的新手:(
I'm new to postgres :(
我有一个带有Id
和name
字段的表product
I have a table product
with Id
and name
field
推荐答案
如果使用id
列创建了表product
,则该序列将不简单地称为product
,而是product_id_seq
(是${table}_${column}_seq
).
If you created the table product
with an id
column, then the sequence is not simply called product
, but rather product_id_seq
(that is, ${table}_${column}_seq
).
这是您需要的ALTER SEQUENCE
命令:
ALTER SEQUENCE product_id_seq RESTART WITH 1453
您可以使用psql中的\ds
命令查看数据库中的序列.如果您执行\d product
并查看列的默认约束,则nextval(...)
调用也将指定序列名称.
You can see the sequences in your database using the \ds
command in psql. If you do \d product
and look at the default constraint for your column, the nextval(...)
call will specify the sequence name too.
这篇关于在postgres中重置自动增量计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!