agora inbox for pgsql-admin@postgresql.org  
help / color / mirror / Atom feed
From: Udo Polder <udo.polder@gmail.com>
To: pgsql-admin@lists.postgresql.org
Subject: Problem with "on conflict"
Date: Wed, 26 Mar 2025 17:15:47 +0100
Message-ID: <939e57d2-9294-4557-b436-eb5e9b268f6f@gmail.com> (raw)

Hi all. I have some really strange behavior with postgres and 'on conflict'.
I had some error today at a customer and i figured out, the problem is 
triggered by postgres doing an insert on a table with wrong data (not 
even provided), when it should insert the data.

After some playing around with the query, the error just went away, 
magically ….
Here you can see, that the insert is updating stuff:

There also is a trigger on the db:

CREATE OR REPLACE FUNCTION fn_hut_bundle_create_id() returns TRIGGER AS $$
begin
     if new.bundle_id is null or new.bundle_id='' then
         NEW.bundle_id = concat('HB-', nextval('seq_hut_bundle_id'));
     end if;

     return NEW;
END;
$$ LANGUAGE plpgsql;
create trigger tr_hut_bundle_id before insert on hut_bundle for each row 
EXECUTE FUNCTION fn_hut_bundle_create_id();





now working:


Can someone give me some hint, what the problem could be? After my 
„playing“ the error can not be reproduced any longer, and the statement 
is inserting stuff like it should.
i played with null and '' as a primary key(bundle_id)

Postgres is:
PostgreSQL 14.1 (Debian 14.1-1.pgdg110+1) on x86_64-pc-linux-gnu, 
compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit

Any help would be very welcome ....

Thanks

Attachments:

  [image/png] ti600gsoOaUj04Ng.png (119.4K, ../939e57d2-9294-4557-b436-eb5e9b268f6f@gmail.com/3-ti600gsoOaUj04Ng.png)
  download | view image

  [image/png] U4iCI1t7CX28e3oM.png (111.0K, ../939e57d2-9294-4557-b436-eb5e9b268f6f@gmail.com/4-U4iCI1t7CX28e3oM.png)
  download | view image

view thread (3+ messages)  latest in thread

Message-ID: <939e57d2-9294-4557-b436-eb5e9b268f6f@gmail.com>
Permalink:  ../939e57d2-9294-4557-b436-eb5e9b268f6f@gmail.com/
Also on:    postgresql.org/message-id/939e57d2-9294-4557-b436-eb5e9b268f6f@gmail.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: udo.polder@gmail.com, pgsql-admin@lists.postgresql.org
  Subject: Re: Problem with "on conflict"
  In-Reply-To: <939e57d2-9294-4557-b436-eb5e9b268f6f@gmail.com>

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

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