Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1txTfa-009xy2-TI for pgsql-admin@arkaria.postgresql.org; Wed, 26 Mar 2025 16:31:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1txTfY-006LcH-Jw for pgsql-admin@arkaria.postgresql.org; Wed, 26 Mar 2025 16:31:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1txTfY-006Lc9-7K for pgsql-admin@lists.postgresql.org; Wed, 26 Mar 2025 16:31:56 +0000 Received: from p-east3-cluster2-host10-snip6-10.eps.apple.com ([2a01:b747:3006:207::67] helo=p00-icloudmta-asmtp-us-east-2d-10-percent-1.p00-icloudmta-asmtp-vip.icloud-mail-production.svc.kube.us-east-2d.k8s.cloud.apple.com) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1txTfW-001Gps-1W for pgsql-admin@lists.postgresql.org; Wed, 26 Mar 2025 16:31:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=1a1hai; bh=zy4B20vpmhyRr+yeskRoPf8LhQ4NJT+TzhCvcmuXkzw=; h=Content-Type:Mime-Version:Subject:From:Date:Message-Id:To:x-icloud-hme; b=fcP99v7kbQt9qPsZuZpKuj72QGGQbwF3hg55nvYcPN08MaxC4EoMxw5Ra8Aiqjvdm FL2n4xlIhXBVheQ7I+XeFvM8+kpqm7SuAZn9aTa2EMj4t4hQknc+ecQouiCncYQDh4 WkYzy+kEcbTY1s2ohCm5ye8w6TpSUctK9yhNV2vEPnC1/74gVQqG71xdoleC8hM53f fIXiXMiDsS18VZk+2cP8U5CJXlOwHqq7g6K5oMg5WiLmxuOgK5VjeoaaC2yER1s5dB vyxiofqRbEiEzB4z55f3OlJYorIwQ/F+gz3plKJl7lE6ktkoAS244/JpqXxwrF8JzP BN4HJiWUjZtIQ== Received: from smtpclient.apple (qs-asmtp-me-k8s.p00.prod.me.com [17.57.155.37]) by p00-icloudmta-asmtp-us-east-2d-10-percent-1.p00-icloudmta-asmtp-vip.icloud-mail-production.svc.kube.us-east-2d.k8s.cloud.apple.com (Postfix) with ESMTPSA id CAD4A1800C45; Wed, 26 Mar 2025 16:31:50 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.10\)) Subject: Re: Problem with "on conflict" From: Rui DeSousa In-Reply-To: <939e57d2-9294-4557-b436-eb5e9b268f6f@gmail.com> Date: Wed, 26 Mar 2025 12:31:47 -0400 Cc: pgsql-admin@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <5835F92A-3382-4B66-84EA-3DFB02D0D142@icloud.com> References: <939e57d2-9294-4557-b436-eb5e9b268f6f@gmail.com> To: Udo Polder X-Mailer: Apple Mail (2.3696.120.41.1.10) X-Proofpoint-GUID: J6A4hpNmXSRvZrtIT2VtNORWqY1o7YFy X-Proofpoint-ORIG-GUID: J6A4hpNmXSRvZrtIT2VtNORWqY1o7YFy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1095,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-26_08,2025-03-26_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 bulkscore=0 clxscore=1011 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2503260101 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Mar 26, 2025, at 12:15 PM, Udo Polder wrote: >=20 > 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. >=20 > After some playing around with the query, the error just went away, = magically =E2=80=A6.=20 > Here you can see, that the insert is updating stuff: >=20 > There also is a trigger on the db: >=20 > CREATE OR REPLACE FUNCTION fn_hut_bundle_create_id() returns TRIGGER = AS $$ > begin > if new.bundle_id is null or new.bundle_id=3D'' then > NEW.bundle_id =3D concat('HB-', nextval('seq_hut_bundle_id')); > end if; >=20 > 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(); >=20 > >=20 >=20 >=20 > now working: > >=20 > Can someone give me some hint, what the problem could be? After my = =E2=80=9Eplaying=E2=80=9C 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) >=20 > 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 >=20 > Any help would be very welcome .... >=20 > Thanks >=20 To me it looks like the record already existed and the on conflict = update occurred. Given that hut_id is not updated on conflict; the old = value remained. Was the sequence recycled or was 'HB-32=E2=80=99 = created manually beforehand?