Re: Reset Sequence number

Поиск
Список
Период
Сортировка
От Thomas Kellerer
Тема Re: Reset Sequence number
Дата
Msg-id ov3lk5$eke$1@blaine.gmane.org
обсуждение исходный текст
Ответ на [GENERAL] Reset Sequence number  (Brahmam Eswar <brahmam1234@gmail.com>)
Список pgsql-general
Brahmam Eswar schrieb am 22.11.2017 um 10:36:
> 
> we are in process of migrating to postgres and need to reset the
> sequence number with highest value of table key. I want to make it
> procedural to do that as mentioned below, But it's throwing an error

> DO $$
>  DECLARE
>  SEQ BIGINT;
>  BEGIN 
>  
>  SEQ:=(SELECT MAX(ID) FROM TABLE_1);
>  ALTER SEQUENCE TABLE_1_SEQ  RESTART WITH SEQ;
>   
>  END$$; 
>  
> Error : syntax error at or near "SEQ"

No need for a PL/pgSQL block.

You can do that with a plain SQL statement using setval():
  select setval('table_1_seq', (select max(id) from table1));




В списке pgsql-general по дате отправления:

Предыдущее
От: Wèi Cōngruì
Дата:
Сообщение: Re: [GENERAL] Reset Sequence number
Следующее
От: Alexander Pyhalov
Дата:
Сообщение: duplicate primary key