From: | Oliver Elphick <olly(at)lfix(dot)co(dot)uk> |
---|---|
To: | Sterpu Victor <victor(at)ambra(dot)ro> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: sequence problem - many rows |
Date: | 2005-11-29 18:43:40 |
Message-ID: | 1133289820.10517.93.camel@linda.lfix.co.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Tue, 2005-11-29 at 18:00 +0200, Sterpu Victor wrote:
> I have the following table
...
> And the sequence for the id column:
> CREATE SEQUENCE cachedgroupmembers_id_seq CACHE 1000;
>
> Now the table is empty and I try to insert a row in this table:
> INSERT INTO cachedgroupmembers(groupid) values(55);
> And it works.
>
> Next I populate the table wittt aprox 700.000 records.
Now you need to set the sequence value:
SELECT setval('cachedgroupmembers_id_seq',(select max(id) FROM
cachedgroupmembers);
> And I do again "INSERT INTO cachedgroupmembers(groupid) values(55);".
> The error is : ERROR: duplicate key violates unique constraint
> "cachedgroupmembers_pkey"
That was because the sequence was trying to reuse one of the 700,000
values you just loaded.
--
Oliver Elphick olly(at)lfix(dot)co(dot)uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA
========================================
Do you want to know God? http://www.lfix.co.uk/knowing_god.html
From | Date | Subject | |
---|---|---|---|
Next Message | Tyler MacDonald | 2005-11-29 18:50:01 | Re: undefined behaviour for sub-transactions? |
Previous Message | Tom Lane | 2005-11-29 18:23:16 | Re: Installation trouble - Solved (?) |