Re: Equivalent for AUTOINCREMENT?

Поиск
Список
Период
Сортировка
От Michelle Konzack
Тема Re: Equivalent for AUTOINCREMENT?
Дата
Msg-id 20081106194248.GB27226@tamay-dogan.net
обсуждение исходный текст
Ответ на Re: Equivalent for AUTOINCREMENT?  (Craig Ringer <craig@postnewspapers.com.au>)
Ответы Re: Equivalent for AUTOINCREMENT?  (Craig Ringer <craig@postnewspapers.com.au>)
Список pgsql-general
Halle Craig,

Am 2008-11-05 20:37:31, schrieb Craig Ringer:
> If you really, truly need gapless sequences, there are some options. I
> posted about them recently on another thread. The archives will contain
> that post and many others from many people on the same topic. Be aware,
> though, that gapless sequences have some NASTY performance consequences.

Since this "NASTY performance consequences" would only  hit  the  INSERT
statement and it is very unlikely that I  have  concurence  WRITE/INSERT
access, it is a minor problem.

> Design your application not to expect your primary keys to be gapless.
> If it requires contiguous sequences for something, generate them at
> query time instead of storing them as primary keys. If the contiguous
> sequence numbers must also be stable over the life of the record, try to
> redesign to avoid that requirement if at all possible.

Yes it is a requirement...  and this is, why I have  tried  to  get  the
highest value of the column "serno".

> CREATE TABLE id_counter ( last_used INTEGER NOT NULL );
> INSERT INTO id_counter ( last_used ) VALUES ( -1 );
> --
> UPDATE id_counter SET last_used = last_used + 1;

> --
> INSERT INTO sometable ( id, blah ) VALUES ( (SELECT last_used FROM
> id_counter), 'blah');

Thank you for the example....
I will try it out now.

Thanks, Greetings and nice Day/Evening
    Michelle Konzack
    Systemadministrator
    24V Electronic Engineer
    Tamay Dogan Network
    Debian GNU/Linux Consultant


--
Linux-User #280138 with the Linux Counter, http://counter.li.org/
##################### Debian GNU/Linux Consultant #####################
Michelle Konzack   Apt. 917                  ICQ #328449886
+49/177/9351947    50, rue de Soultz         MSN LinuxMichi
+33/6/61925193     67100 Strasbourg/France   IRC #Debian (irc.icq.com)

Вложения

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

Предыдущее
От: Thomas Kellerer
Дата:
Сообщение: UPDATE tuples with a sub-select
Следующее
От: Michelle Konzack
Дата:
Сообщение: Re: Equivalent for AUTOINCREMENT?