From: | Arturo Perez <aperez(at)hayesinc(dot)com> |
---|---|
To: | Alban Hertroys <alban(at)magproductions(dot)nl> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Problems with sequences |
Date: | 2006-09-07 11:15:43 |
Message-ID: | C32F9C07-D9A4-423E-AF7C-73F7741F71C8@hayesinc.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Sep 7, 2006, at 5:35 AM, Alban Hertroys wrote:
> Arturo Perez wrote:
>> What happens is that if I do a select nextval('seq') I get a number
>> that's lower than the
>> max primary key id. This is inspite of my doing
>> SELECT setval('seq', ((SELECT MAX(seq_ID) FROM table)+1))
>> ALTER SEQUENCE seq RESTART WITH <max + 1>;
>> select pg_catalog.setval(seq, <max+1>, true);
>
> This seems to be a bit over the top;
> SELECT setval('seq', (SELECT MAX(seq_ID) FROM table)
> should be enough. Even the +1 isn't necessary, as the first value
> the sequence will return is already 1 higher than the value
> retrieved from MAX.
Note that all of the above was in an attempt to reset the sequence to
the proper value. I'm beginning to think that it's a library problem
as this morning I get:
iht=> select max(article_id) from article;
max
------
4992
(1 row)
iht=> select nextval('pk_article');
nextval
---------
4986
(1 row)
Assuming the sequence number is being used correctly why would they
be 6 apart?
>
> Are you sure you're using the correct sequence(s) to retrieve your
> column values for the problematic table(s)? How do you set the
> values for seqID?
I tried statement logging but I am not sure it reported anything
useful. When I get into work I'll send in those logs.
-arturo
From | Date | Subject | |
---|---|---|---|
Next Message | Stefan Schwarzer | 2006-09-07 11:39:06 | Re: Replace NULL values |
Previous Message | Valentin Militaru | 2006-09-07 11:12:57 | Fwd: Help using user rights |