pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: hubert depesz lubaczewski <depesz@depesz.com>
To: Wells Oliver <wells.oliver@gmail.com>
Cc: David G. Johnston <david.g.johnston@gmail.com>
Cc: pgsql-admin <pgsql-admin@postgresql.org>
Subject: Re: nextval() on serial using old, existing value on insert?
Date: Thu, 11 May 2023 14:38:21 +0200
Message-ID: <ZFzhvT/4cvUTRlF2@depesz.com> (raw)
In-Reply-To: <CAOC+FBVz0MhyA4oUwEHbtvCVQV-Hh9n1esA-1OMMt=N6LZb_Vw@mail.gmail.com>
References: <CAOC+FBWAzy8MDbwE2XJGsi8eV=QCuSS8orgAEdyOLr37_Z4ByQ@mail.gmail.com>
	<CAKFQuwaV9z4xUoxaqLx0_-7UjaafWX3O0=1Rsu4EDi87PTxUrQ@mail.gmail.com>
	<CAOC+FBWNpEvA9mSj3_wfhc2PPpeEr5BBshaN4trbXvgPgep0wQ@mail.gmail.com>
	<CAOC+FBVz0MhyA4oUwEHbtvCVQV-Hh9n1esA-1OMMt=N6LZb_Vw@mail.gmail.com>

On Wed, May 10, 2023 at 10:06:28PM -0700, Wells Oliver wrote:
> As a follow up, I've selected max(common_key) from the table and
> setval()'ed on the sequence to that +1 and I think that should make this go
> away. Any reason why that's insane?

If you're on pg 10 or newer, you can make the id to be "generated always
as identity" which will make it impossible to provide id value from
user, thus making the problem impossible to happen.

Best regards,

depesz






view thread (10+ messages)  latest in thread

Message-ID: <ZFzhvT/4cvUTRlF2@depesz.com>
Permalink:  ../ZFzhvT%2F4cvUTRlF2@depesz.com/
Also on:    postgresql.org/message-id/ZFzhvT/4cvUTRlF2@depesz.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: depesz@depesz.com, wells.oliver@gmail.com, david.g.johnston@gmail.com
  Subject: Re: nextval() on serial using old, existing value on insert?
  In-Reply-To: <ZFzhvT/4cvUTRlF2@depesz.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox