Problem with "on conflict"

From: Udo Polder <udo(dot)polder(at)gmail(dot)com>
To: pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: Problem with "on conflict"
Date: 2025-03-26 16:15:47
Message-ID: 939e57d2-9294-4557-b436-eb5e9b268f6f@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

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

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Rui DeSousa 2025-03-26 16:31:47 Re: Problem with "on conflict"
Previous Message Laurenz Albe 2025-03-20 15:59:08 Re: Background writer not much active