| From: | Heiko Klein <Heiko(dot)Klein(at)met(dot)no> |
|---|---|
| To: | pgsql-general(at)postgresql(dot)org |
| Subject: | triggering a sequence |
| Date: | 2002-04-05 14:12:36 |
| Message-ID: | 15533.45268.931250.887974@polar.oslo.dnmi.no |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | mixo | 2002-04-05 14:14:15 | dates |
| Previous Message | Andreas Scherbaum | 2002-04-05 13:40:18 | Re: Porting from MySql - meta data issues |