Обсуждение: reinitialise serial counter

Поиск
Список
Период
Сортировка

reinitialise serial counter

От
Indraneel Majumdar
Дата:
Hi,

I have a table

create table test (id serial, name text);

after inserting values and doing delete from test if I try to insert
values again, the id starts from where it left off previously. How can I
get the serial counter to restart from 1 ? is it anything to do with
setval(). How to use the setval?

thanks,
Indraneel

/************************************************************************.
# Indraneel Majumdar                  ¡  E-mail: indraneel@123india.com  #
# Bioinformatics Unit (EMBNET node),  ¡  URL: http://scorpius.iwarp.com  #
# Centre for DNA Fingerprinting and Diagnostics,                         #
# Hyderabad, India - 500076                                              #
`************************************************************************/



RE: reinitialise serial counter

От
"Edmar Wiggers"
Дата:
> after inserting values and doing delete from test if I try to insert
> values again, the id starts from where it left off previously. How can I
> get the serial counter to restart from 1 ? is it anything to do with
> setval(). How to use the setval?

The serial value is implemented using a sequence object (see the docs). Once
a sequence returns a number it will never return it again (that's what
sequences are for!).

A serial field is not a good approach if you always want to start numbering
at 1.

Yours sincerely,

Edmar Wiggers
BRASMAP Information Systems
+55 48 9960 2752