Re: [PERFORM] Auto generate number in Postgres-9.1.

Поиск
Список
Период
Сортировка
От Andreas Karlsson
Тема Re: [PERFORM] Auto generate number in Postgres-9.1.
Дата
Msg-id efd88f08-1a8e-c883-9842-38fe63588c18@proxel.se
обсуждение исходный текст
Ответ на Re: [PERFORM] Auto generate number in Postgres-9.1.  (Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>)
Список pgsql-performance
On 03/20/2017 03:08 PM, Dinesh Chandra 12108 wrote:
> But on deletion it's not automatically re-adjusting the id's.
>
> Do I need to create trigger for this??

It is possible to do but I advice against adjusting the IDs on DELETE
due to to do so safely would require locking the entire table in the
trigger.

Note that serial columns will also get holes on ROLLBACK. In general I
think the right thing to do is accept that your ID columns can get a bit
ugly.

For example:

CREATE TABLE t (id serial);

INSERT INTO t DEFAULT VALUES;

BEGIN;

INSERT INTO t DEFAULT VALUES;

ROLLBACK;

INSERT INTO t DEFAULT VALUES;

Gives us the following data in the table:

  id
----
   1
   3
(2 rows)

Andreas


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

Предыдущее
От: Dinesh Chandra 12108
Дата:
Сообщение: Re: [PERFORM] Auto generate number in Postgres-9.1.
Следующее
От: James Parks
Дата:
Сообщение: [PERFORM] Optimizing around retained tuples