在postgresql中更改`* _id_seq`表的值

时间:2013-02-01 12:14:41

标签: sql postgresql

我在postgresql中有以下表格myapp_mymodel_id_seq

    Column     |  Type   |           Value            
---------------+---------+----------------------------
 sequence_name | name    | myapp_mymodel_id_seq
 last_value    | bigint  | 3
 start_value   | bigint  | 1
 increment_by  | bigint  | 1
 max_value     | bigint  | 9223372036854775807
 min_value     | bigint  | 1
 cache_value   | bigint  | 1
 log_cnt       | bigint  | 32
 is_cycled     | boolean | f
 is_called     | boolean | t

如何将3Value下的last_value更改为40

我尝试更新last_value,但无法识别该列。

UPDATE myapp_mymodel_id_seq SET Value=40 WHERE Value=3;

ERROR:  column "value" does not exist

2 个答案:

答案 0 :(得分:3)

select setval('myapp_mymodel_id_seq', 40);

有关详细信息,请参阅手册:http://www.postgresql.org/docs/current/static/functions-sequence.html

答案 1 :(得分:-2)

更新myapp_mymodel_id_seq SET last_value = 40 WHERE last_value = 3;