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 1kwWYc-0000KR-7E for pgsql-general@arkaria.postgresql.org; Mon, 04 Jan 2021 20:34:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kwWYb-0004YK-5f for pgsql-general@arkaria.postgresql.org; Mon, 04 Jan 2021 20:34:25 +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 1kwWYa-0004YD-Rx for pgsql-general@lists.postgresql.org; Mon, 04 Jan 2021 20:34:24 +0000 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kwWYY-0007jx-6w for pgsql-general@lists.postgresql.org; Mon, 04 Jan 2021 20:34:24 +0000 Received: by mail-ej1-x629.google.com with SMTP id d17so38433622ejy.9 for ; Mon, 04 Jan 2021 12:34:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=SbSh8ED64/sk4y/jEAHQgNMf7LEw3KSiO4OJr1Zr2dc=; b=pzqszgTdI1U0MUxxlDrbRswnaqOBDl9ITqDTnBbrpZ1ZAqBO758+cnu0N2T1HGH86M XoR4Ld3zHXYJgUAx2yMZyR57xjM/yylrw8E6zwY/UQim7n/dQiUtbXVrEA5vTTzulrjd w7gk/WhURkoIhuH3zjgSYxjHWonDDXIWSOU901x0rtfE7vWLTHnRPzpmSjIpQP9CuLBF lnjhsEKR1UuuFGhkWDyG2FFCVWN0M0tAVowv6f1y6TsfYywrDKgezNv798sYRzGQFadK gTpf34OWTargYBa9P3zM1wHTkZHW0USzZkt4msdArhIObMHXGnyB0OBz7ImNT3j7aZ9G S7xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=SbSh8ED64/sk4y/jEAHQgNMf7LEw3KSiO4OJr1Zr2dc=; b=XeYYde9x0RXgZHm5Cu8oEhmlVrWh3XCz6/bYfginSsFmwTHR9QCj4mNies+/Wn2Msn QiHFLNbdb20RmzwWijD3i1HJKhTIWAa3TrRh/mFCmgx37CBIVUFuY3luL1zgrIvpJh9s u/3u6CNUii+cFJcyvhhCpczJV/yolS9CIe+hLxOi4W/qUiiqpS60qjSEMKuFf1zh3/vs 54J6MdOojmxL4hmoLDuUz5Tkjk9mtFF4SFTLHtRTmXQRLzq44AZLYqoYhpCZp6WzSAC0 1tUqXuuW3qpOsC+TPld0CaPQN8HEfqoH8ux9zeajZow5mb1EaAy2HpkoH1Q5q1Xlkwsp /1Bw== X-Gm-Message-State: AOAM533x5/j8po4BYF5OVTaOmM9YP4duzpwSulwhVrMhWEluyFKlmOvG fEk2cQ5kBuZlsN9XGLaQmvU= X-Google-Smtp-Source: ABdhPJyRRGYNKdSddmQlyZwvxxc1FQWHlfT9wPG4teFmdxD2KXpUKjJgSzcEu6/774TzbyMiiBTw6Q== X-Received: by 2002:a17:906:94c5:: with SMTP id d5mr66264499ejy.427.1609792460622; Mon, 04 Jan 2021 12:34:20 -0800 (PST) Received: from hollewijn.internal (217-19-30-105.dsl.cambrium.nl. [217.19.30.105]) by smtp.gmail.com with ESMTPSA id n22sm44031061edr.11.2021.01.04.12.34.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jan 2021 12:34:19 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.17\)) Subject: Re: Trigger with conditional predicates From: Alban Hertroys In-Reply-To: <2BC0544B-F37E-47C2-AC17-033C5B28A477@mikatiming.de> Date: Mon, 4 Jan 2021 21:34:16 +0100 Cc: "pgsql-general@lists.postgresql.org" Content-Transfer-Encoding: quoted-printable Message-Id: References: <47B9A4A8-9A09-4801-989B-AE2C657443DC@gmail.com> <2BC0544B-F37E-47C2-AC17-033C5B28A477@mikatiming.de> To: Dirk Mika X-Mailer: Apple Mail (2.3445.104.17) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On 4 Jan 2021, at 20:02, Dirk Mika wrote: >=20 >>> On 1 Jan 2021, at 16:56, Dirk Mika wrote: >>>=20 >>> Hi all and a happy new Year! >>>=20 >>> We have an Oracle schema that is to be converted to PostgreSQL, = where conditional predicates are used in some triggers. >>>=20 >>> In particular, columns are populated with values if they are not = specified in the update statement which is used. >>> Usually with an expression like this: >>>=20 >>> IF NOT UPDATING('IS_CANCELED') >>> THEN >>> :new.is_canceled :=3D ...; >>> END IF; >>>=20 >>> I have not found anything similar in PostgreSQL. What is the common = approach to this problem? >=20 >> Can't you use column defaults to handle these cases? >=20 > That would work for inserts, but not for updates. Usually, if you don=E2=80=99t mention a column in an UPDATE, you want = the value to remain as it was, which is precisely what happens by = default. That certainly makes sense to me when you=E2=80=99re dealing = with an application that doesn=E2=80=99t know about the existence of = said column; overwriting an existing value that some other application = put there looks like a problem to me. But of course, that depends a lot = on what you=E2=80=99re trying to achieve. What is your use-case that that is not the desired behaviour? Or are we = talking about a mixed problem here, where this approach works for some = fields, but other fields (such as a status change date) always need to = be updated (regardless of whether a value was specified)? Regards, Alban Hertroys -- If you can't see the forest for the trees, cut the trees and you'll find there is no forest.