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 1mfNe8-0006Hy-SJ for pgsql-general@arkaria.postgresql.org; Tue, 26 Oct 2021 14:41:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mfNe7-0005VJ-IE for pgsql-general@arkaria.postgresql.org; Tue, 26 Oct 2021 14:41:47 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mfNe7-0005V9-4v for pgsql-general@lists.postgresql.org; Tue, 26 Oct 2021 14:41:47 +0000 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mfNe0-0003rY-TJ for pgsql-general@postgresql.org; Tue, 26 Oct 2021 14:41:46 +0000 Received: by mail-ed1-x532.google.com with SMTP id 5so14555632edw.7 for ; Tue, 26 Oct 2021 07:41:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=PjqN9ZidJy9t5CCp+qe3BzzTE8r+5HVxVWhCSy7iZsE=; b=bvis0A2PsCl9SWV1CgFw78PnnVSNPKd/54etTqc9R4yRCu6lHJHub7c+y0rmA3K5wr h4T1FIJjxNOB2MX0YqEaeR3IFODQ/p2eb4h0P7eeNXhKH27z8Nhp5BGXVurTTCd5hT5d w94OJR/1fqLyb2BWSYn0C6FEnYrIokOtp5Z+XKry8Vu6VUWdhvjaJnKIMdExb1F3gzbQ or4ltPwZMJScpkiqCg07giJbtnnz268DI3xBJrHtC5l+77rXOantVag2FR9Ype1ULB+d QaGX9ybpPbWMQoX2OZuurgEGB4aSkzKdJD7PvhUFvNHN1KdgSWZddp3ftshRoGG2p2H2 04Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=PjqN9ZidJy9t5CCp+qe3BzzTE8r+5HVxVWhCSy7iZsE=; b=veTU28KBCLlNuSM6+EFZRjPa6OIWtuYWB1bOzNUWegw72j4ARfek+LugebwGEAQvnq cFsDuA89EeSe8sNjK1ELfXPBbUHVAEfAVqP31wXwo8+7YUx42A2VhCbdc6PcPv+9kCz9 DrO1ZfnGq55nVm0tjtuaDB8GXEsK68k/V6jRDXg4U2uA0uyov8K4Z7pdLzj9fR23O+ah 3O2gWwtWsIiWQ5iNy1s3omZ3QzsqoHp5xz5hoKXkQVvY7qD6FMxlD84OJcW31lnCBqts xCrIoeDX8D70lml2pSJvjWJlzf0nASAfDLjMzF3nOj6/fr+y2wLeCyzsZeqCghXB4QoF j/7A== X-Gm-Message-State: AOAM532dpN0iSyvZx3ptX6rVaDx5mVqEiz2jQq3V/mZunmoEyALyzTUK 9YCtzyUER9j1g7FzZAyffiA= X-Google-Smtp-Source: ABdhPJw1ug4xRQ+/ePJ+JeVsYXHXBoZjS4jSHqQOni0R8222wBfnzBYj3ffAME96JNhcw1jwU9lW1g== X-Received: by 2002:a05:6402:5252:: with SMTP id t18mr34709759edd.129.1635259169781; Tue, 26 Oct 2021 07:39:29 -0700 (PDT) Received: from hollewijn.internal (217-19-30-105.dsl.cambrium.nl. [217.19.30.105]) by smtp.gmail.com with ESMTPSA id go41sm6249246ejc.32.2021.10.26.07.39.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Oct 2021 07:39:29 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\)) Subject: Re: Determining if a table really changed in a trigger From: Alban Hertroys In-Reply-To: Date: Tue, 26 Oct 2021 16:39:28 +0200 Cc: Mitar , Postgres General Content-Transfer-Encoding: quoted-printable Message-Id: <34832EC6-D3E4-4596-A043-1A199AB04F89@gmail.com> References: To: Marcos Pegoraro X-Mailer: Apple Mail (2.3608.120.23.2.7) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 26 Oct 2021, at 16:16, Marcos Pegoraro wrote: >=20 >=20 >> Don=E2=80=99t use this approach with JSON (as opposed to JSONB) type = fields though, a single extra space in the JSON structure would already = lead to a difference, as would other formatting differences. >>=20 > I don=C2=B4t think two equal values being converted to json will be = different in any way. If row_to_json of both are different, I suppose = both record really are different, no ?=20 For row_to_json, as it=E2=80=99s the system that combines the fields in = a row into a JSON structure and it probably would do that in the same = way each time. The OP however has a field of type JSON in their table, and that can = contain the same information between the OLD and NEW fields formatted in = a slightly different way. For example: =3D> with x as ( select '{ "x": 1, "y": 2 }'::json union all select '{ "y": 2, "x": 1 }'::json ) select row(x.json)::text, md5(row(x.json)::text) from x; row | md5 =20 ----------------------------+---------------------------------- ("{ ""x"": 1, ""y"": 2 }") | 84df40e8660dcf371d89dbf5d6a61c3d ("{ ""y"": 2, ""x"": 1 }") | abd6db88c2526be6ea97570aeec7e020 (2 rows) Whereas: =3D> with x as ( select '{ "x": 1, "y": 2 }'::jsonb union all select '{ "y": 2, "x": 1 }'::jsonb ) select row(x.jsonb)::text, md5(row(x.jsonb)::text) from x; row | md5 =20 --------------------------+---------------------------------- ("{""x"": 1, ""y"": 2}") | d5a6dbdec7a5bfe0dc99e090db30322e ("{""x"": 1, ""y"": 2}") | d5a6dbdec7a5bfe0dc99e090db30322e (2 rows) Alban Hertroys -- There is always an exception to always.