Re: Primary key definition?
От | Michael Lewis |
---|---|
Тема | Re: Primary key definition? |
Дата | |
Msg-id | CAHOFxGp+kTQDW=eEZm=hm0aJRHPcozVTv0k2QhydtqBr-PZHHQ@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Primary key definition? (Ron <ronljohnsonjr@gmail.com>) |
Список | pgsql-general |
> CREATE TABLE books (
> id SERIAL PRIMARY KEY,
>
> Which has the advantage of not having to manually create the sequences. Will
> this also enforce that the "internally created sequence" will be initialized
> to a value above the maximum key in use on a pg_restore?
I think you will still run into the same issue if your sequence is not getting the proper value as max(id) or max(id) +1, not sure which is actually needed. You may get some benefits from using IDENTITY rather than the pseudo-type of serial, as described in this blog post-
Still, depending on how you are doing the data restore, you may need something like this to ensure the sequence is updated.
select setval( 'table_id_seq', ( select max(id) + 1 from table ) );
В списке pgsql-general по дате отправления: