Re: Problem with SqlState=23505 when inserting rows

From: Michael Lewis <mlewis(at)entrata(dot)com>
To: Werner Kuhnle <wek(at)kuhnle(dot)com>
Cc: PostgreSQL General <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Problem with SqlState=23505 when inserting rows
Date: 2020-01-15 16:51:47
Message-ID: CAHOFxGoaDbQ3Ah5gEz4Dkj9eyvbVBxz+cWHprNoxxMvzbBSWQQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Jan 15, 2020 at 9:41 AM Werner Kuhnle <wek(at)kuhnle(dot)com> wrote:

> I've tried to using the newer definition:
> id int GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY
> but that does not solve the problem.
>
> Is there a way to define id columns to that when the database provides
> values,
> it recognizes already existing values avoiding conflicts.
>

You'll need to run something like the below to set the next value to the
max current value. You'll just have to figure out the name of the sequence
that is automatically created whether you use the pseudo type serial, or
the newer IDENTITY option. Both are implemented with a sequence.

--set sequence to max ID on a table
select setval( 'table_name_id_seq', ( select max(id) + 1 from table_name )
);

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Konireddy Rajashekar 2020-01-15 18:18:39 OID out of range
Previous Message Adrian Klaver 2020-01-15 16:51:34 Re: Problem with SqlState=23505 when inserting rows