Re: Problems with sequences
От | Alban Hertroys |
---|---|
Тема | Re: Problems with sequences |
Дата | |
Msg-id | 44FFE7E2.7050806@magproductions.nl обсуждение исходный текст |
Ответ на | Problems with sequences ("Arturo Perez" <aperez@hayesinc.com>) |
Ответы |
Re: Problems with sequences
|
Список | pgsql-general |
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. 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? Also note that a SERIAL type column is simply a macro for creating an INT4 type column with a DEFAULT nextval('...'). You can easily change your schema to include the defaults. -- Alban Hertroys alban@magproductions.nl magproductions b.v. T: ++31(0)534346874 F: ++31(0)534346876 M: I: www.magproductions.nl A: Postbus 416 7500 AK Enschede // Integrate Your World //
В списке pgsql-general по дате отправления: