Re: Primary key definition? - Mailing list pgsql-general

From Michael Lewis
Subject Re: Primary key definition?
Date
Msg-id CAHOFxGp+kTQDW=eEZm=hm0aJRHPcozVTv0k2QhydtqBr-PZHHQ@mail.gmail.com
Whole thread Raw
In response to Re: Primary key definition?  (Ron <ronljohnsonjr@gmail.com>)
List 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 by date:

Previous
From: Jeff Lanzarotta
Date:
Subject: SQL Error [0A000]: ERROR: nondeterministic collations are notsupported for LIKE
Next
From: "Boylan, Ross"
Date:
Subject: Upgrade mode will prevent the installer .... (pgAgent)