Re: Determining if a table really changed in a trigger

From: Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
To: Mitar <mmitar(at)gmail(dot)com>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Determining if a table really changed in a trigger
Date: 2021-10-26 13:36:13
Message-ID: CAB-JLwaLz3d31QSTAg_+zVEK3XLJ=Jw8VZjm43E=xbY6v31TzQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>
>
> PERFORM * FROM ((TABLE old_table EXCEPT TABLE new_table) UNION ALL
> (TABLE new_table EXCEPT TABLE old_table)) AS differences LIMIT 1;
> IF FOUND THEN
> ... changed ...
> END IF;
>
> Maybe converting new and old records to json and text
PERFORM * FROM (select ID, row_to_json(O.*)::text Old_Values,
row_to_json(N.*)::text New_Values from old_table o full outer join
new_table N using(ID) where Old_Values is distinct from New_Values) as
differences LIMIT 1;

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Miles Elam 2021-10-26 13:45:45 Re: Determining if a table really changed in a trigger
Previous Message David G. Johnston 2021-10-26 13:23:55 Re: How to copy rows into same table efficiently