pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Werner Kuhnle <wek@kuhnle.com>
To: pgsql-general@lists.postgresql.org
Subject: Problem with SqlState=23505 when inserting rows
Date: Wed, 15 Jan 2020 16:40:47 +0000
Message-ID: <DIIE.00000B1F0000CD69@kuhnle.com> (raw)



Hi,

I'm new to pg and want to port an application and database from ms sql to pg v12.

Together with my application a database containing initial standard data 
which is needed by the application is also installed.
This is done via execution of SQL scripts.

Every table of the db has an id column and id column values are also contained in the SQL script 
which is necessary for consistence.

In MS SQL id columns were defined as
id INT IDENTITY PRIMARY KEY

In PG id columns are defined as
id SERIAL PRIMARY KEY

Importing the SQL script for initial standard data with PG Admin 4 works without any problem.

But afterwards I get error messages with SqlState=23505 when inserting new rows into that databases by my application.
My application does not provide id values when doing INSERT INTO statements so that new id values are automatically provided by the database.

This worked in MS SQL DB without any problems.

But in PG there seem to be conflicts between the row id values of the rows that were
initially imported and the row id values which are automatically provided by the database
if values for id column are missing in INSERT INTO
When automatically providing id values PG seems to ignore the already existing id values.

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.

Any hint is highly appreciated.

Regards

Werner








view thread (3+ messages)  latest in thread

Message-ID: <DIIE.00000B1F0000CD69@kuhnle.com>
Permalink:  ../DIIE.00000B1F0000CD69@kuhnle.com/
Also on:    postgresql.org/message-id/DIIE.00000B1F0000CD69@kuhnle.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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: wek@kuhnle.com
  Subject: Re: Problem with SqlState=23505 when inserting rows
  In-Reply-To: <DIIE.00000B1F0000CD69@kuhnle.com>
  References: <DIIE.00000B1F0000CD69@kuhnle.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