From: | Michael Lewis <mlewis(at)entrata(dot)com> |
---|---|
To: | Ron <ronljohnsonjr(at)gmail(dot)com> |
Cc: | PostgreSQL General <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Primary key definition? |
Date: | 2019-10-22 21:16:33 |
Message-ID: | CAHOFxGp+kTQDW=eEZm=hm0aJRHPcozVTv0k2QhydtqBr-PZHHQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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-
https://www.2ndquadrant.com/en/blog/postgresql-10-identity-columns/
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 ) );
From | Date | Subject | |
---|---|---|---|
Next Message | Boylan, Ross | 2019-10-22 21:30:08 | Upgrade mode will prevent the installer .... (pgAgent) |
Previous Message | Jeff Lanzarotta | 2019-10-22 21:03:59 | SQL Error [0A000]: ERROR: nondeterministic collations are not supported for LIKE |