Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qCW23-0002gh-4h for pgsql-sql@arkaria.postgresql.org; Fri, 23 Jun 2023 01:56:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qCW21-0006Pf-D7 for pgsql-sql@arkaria.postgresql.org; Fri, 23 Jun 2023 01:56:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qCW21-0006PW-4W for pgsql-sql@lists.postgresql.org; Fri, 23 Jun 2023 01:56:13 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qCW1y-0047dx-TN for pgsql-sql@lists.postgresql.org; Fri, 23 Jun 2023 01:56:12 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 35N1u76j4141158; Thu, 22 Jun 2023 21:56:09 -0400 From: Tom Lane To: ProfiVPS Support cc: pgsql-sql@lists.postgresql.org Subject: Re: Strange update behaviour In-reply-to: References: <257ece670da80be9e2d08126aba9c641@profivps.hu> <4115432.1687471882@sss.pgh.pa.us> Comments: In-reply-to ProfiVPS Support message dated "Fri, 23 Jun 2023 01:07:21 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4141156.1687485367.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 22 Jun 2023 21:56:07 -0400 Message-ID: <4141157.1687485367@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ProfiVPS Support writes: > I hope everything is there to enable testing. Thanks for sending a test case! But I think this is a logic bug in your function. There are several updates of app_devices in that function. Adding some "raise notice" commands to track the logic flow, I see that the given case results in # SELECT collectd_insert(CURRENT_TIMESTAMP, = 'DE:AD:A7:14:69:9210.123.4.12', 'ruckusphp', '', 'pstates_enabled', = 'state', '{et}', '{0}', '{1}'); NOTICE: first update happening NOTICE: fourth update happening collectd_insert = ----------------- = (1 row) So it is first doing UPDATE app_devices SET device_state=3D1, device_changets=3D= NOW(), device_updatets=3DNOW() = WHERE device_id=3D dev_id; and then later doing the UPDATE you showed. But at that point, device_state is already 1 so neither of the device_alertstate or device_changets updates change the column's value. It's unobvious that the device_changets update is a no-op because the first UPDATE already set it to the same new value. regards, tom lane