Re: Make an id field max(id)+1 rather than SERIAL

Поиск
Список
Период
Сортировка
От Oliver Elphick
Тема Re: Make an id field max(id)+1 rather than SERIAL
Дата
Msg-id 1032454783.21664.308.camel@linda
обсуждение исходный текст
Ответ на Make an id field max(id)+1 rather than SERIAL  (Rory Campbell-Lange <rory@campbell-lange.net>)
Ответы Re: Make an id field max(id)+1 rather than SERIAL  (Rory Campbell-Lange <rory@campbell-lange.net>)
Список pgsql-novice
On Thu, 2002-09-19 at 15:14, Rory Campbell-Lange wrote:
> I have problems after exporting then importing data into newly created
> databases that the sequence and the indexed serial fields get out of
> alignment.
>
> I wonder if it isn't better to always simply insert ids using some sort
> of function or other procedure to calculate on each insert a new unique
> id number.

After you import data, you must also reset the sequence:

  SELECT setval('sequence_name',
        (SELECT MAX(sequence_column) FROM table));
--
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight, UK
http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "Bring ye all the tithes into the storehouse, that
      there may be meat in mine house, and prove me now
      herewith, saith the LORD of hosts, if I will not open
      you the windows of heaven, and pour you out a
      blessing, that there shall not be room enough to
      receive it."           Malachi 3:10


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

Предыдущее
От: Rory Campbell-Lange
Дата:
Сообщение: Make an id field max(id)+1 rather than SERIAL
Следующее
От: Rory Campbell-Lange
Дата:
Сообщение: Re: Make an id field max(id)+1 rather than SERIAL