Re: nextval() on serial using old, existing value on insert?

From: Doug Reynolds <mav(at)wastegate(dot)net>
To: Holger Jakobs <holger(at)jakobs(dot)com>
Cc: pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Re: nextval() on serial using old, existing value on insert?
Date: 2023-05-11 15:46:26
Message-ID: 010001880b7dfea5-bee3a99a-4115-4921-a569-6fdfe0e35104-000000@email.amazonses.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

If this is a concern, you could use a trigger to ignore the user-provided value or fetch from the sequence.

> On May 11, 2023, at 11:10 AM, Holger Jakobs <holger(at)jakobs(dot)com> wrote:
>
> Am 11.05.23 um 14:38 schrieb hubert depesz lubaczewski:
>>> 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
>
> Impossible to happen by chance. A malicious user could always use OVERRIDING SYSTEM VALUE clause.
>
> Kind Regards,
>
> Holger
>
> --
> Holger Jakobs, Bergisch Gladbach, Tel. +49-178-9759012
>

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Erik Wienhold 2023-05-11 15:54:42 Re: pg_stat_activity query_id
Previous Message kaido vaikla 2023-05-11 15:35:53 Re: pg_stat_activity query_id