triggering a sequence

Поиск
Список
Период
Сортировка
От Heiko Klein
Тема triggering a sequence
Дата
Msg-id 15533.45268.931250.887974@polar.oslo.dnmi.no
обсуждение исходный текст
Список pgsql-general
Hi,

I have seen in the documentation an example of adding a trigger to a
sequence, so no duplicates will be inserted when using the sequence.

Problem is, I can't find it anymore. Can anyone hint me, where it is?

Heiko



And below is the long description:

I have the following table:
create table test (id   serial, text  char(5));

as long as I don't insert a id manually, everything works fine.
(insert into test (text) VALUES '1';)
...
 id | text
----+-------
  1 | 1
  2 | 2
  3 | 3

when I insert the id manually:
insert into test (id, text) VALUES (5,'4');
I get what I expect:
  id | text
----+-------
  1 | 1
  2 | 2
  3 | 3
  5 | 4

But inserting two more rows:
insert into test (text) VALUES ('5');
 id | text
----+-------
  1 | 1
  2 | 2
  3 | 3
  5 | 4
  4 | 5
insert into test (text) VALUES ('6');
ERROR:  Cannot insert a duplicate key into unique index test_id_key

I understand, the sequence will give me 5 as id and that's already
there. I would like the table to look like this:
 id | text
----+-------
  1 | 1
  2 | 2
  3 | 3
  5 | 4    --- here I inserted id manually
  6 | 5
  7 | 6

How do I solve this?

Heiok

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

Предыдущее
От: Andreas Scherbaum
Дата:
Сообщение: Re: Porting from MySql - meta data issues
Следующее
От: mixo
Дата:
Сообщение: dates