Re: Strange update behaviour

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: ProfiVPS Support <support(at)profivps(dot)hu>
Cc: pgsql-sql(at)lists(dot)postgresql(dot)org
Subject: Re: Strange update behaviour
Date: 2023-06-23 01:56:07
Message-ID: 4141157.1687485367@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-sql

ProfiVPS Support <support(at)profivps(dot)hu> 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=1, device_changets=NOW(), device_updatets=NOW()
WHERE device_id= 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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message ProfiVPS Support 2023-06-23 06:56:17 Re: Strange update behaviour
Previous Message ProfiVPS Support 2023-06-22 23:07:21 Re: Strange update behaviour