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 1kvixD-0002Jg-4V for pgsql-general@arkaria.postgresql.org; Sat, 02 Jan 2021 15:36:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kvixB-0000yc-HE for pgsql-general@arkaria.postgresql.org; Sat, 02 Jan 2021 15:36:29 +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 1kvixA-0000yB-1S for pgsql-general@lists.postgresql.org; Sat, 02 Jan 2021 15:36:29 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kvix6-00012o-RP for pgsql-general@lists.postgresql.org; Sat, 02 Jan 2021 15:36:26 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 68BC75C00B0; Sat, 2 Jan 2021 10:36:23 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sat, 02 Jan 2021 10:36:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=9 RnUTH4dJIaMJMvuMdi1n59czlov8VjyMw71tx2XJmE=; b=h33fnkCN1XylHXpBX QIPYYPW06gFNsRrusSES0v5WCv9mHWKHCsT75fu4SM2Wa1PGxbgm9YNV7WWbMC1v B/Ll3mZAYjTWL1iLZpnSohW9vVJAI3DYxPd1yKH6YAGddHfzSQlwXCxiimPJjQ8w 3Y9PLRD0CWLeNunmHnVUkc5JqiNqzx9DNb9UrQMvWofiXDQQ4LGavBwiudoLE9tn Fd1CzbwXMBipOTMP7/9hJvu6adjpvRXutIW4i8Yh18su2zTbD99igjZWr0lY5YLl 3iDQli3DTgomsexQFtQxJIUlr3c4561eGvbTt/1YlEK5UnV3rip6T4AHAb7Dtc6X GPvdQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=9RnUTH4dJIaMJMvuMdi1n59czlov8VjyMw71tx2XJ mE=; b=neXJZbXNEqnLnaXA4RdPqpH/oU3xpQuZBN1ubSH5KZIUgwhm596jxodJ4 Kecr71osJTCj9CgqfIWm2WSm5HZSe1hqWiR7H++XDvbPIeUOwefLzt1ieBHXvfkg 7MwSZtPWfxhs7NCymLOrFnfS3Tf79u3T0C+18jSx3HWvIh823SYzKp7diSdjRpCf Jf6uZ84USGPP9ZKh4uotwd6CiDWgMy9Z9YY6U0xh8YefGHh4O88PAJyw4YtNePMB r4o4VVHzeKAGE+s+i0KJ0tSg82d4CP9DklTL9eIxOhkqB32F8ba0tmQ8KdEWbekR u4cgGJ/iyKcXjr9EkBdyVbVqP7CBw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrvddvledgheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeejhfejveevieevheeuteetveejvddvffegjedvieev ueevgfdvgfelueeuuddtheenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgpd hmihhkrghtihhmihhnghdruggvnecukfhppeejhedrudejvddrudegrddujeenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkh hlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Received: from [192.168.1.4] (75-172-14-17.tukw.qwest.net [75.172.14.17]) by mail.messagingengine.com (Postfix) with ESMTPA id 7784124005B; Sat, 2 Jan 2021 10:36:22 -0500 (EST) Subject: Re: Trigger with conditional predicates To: Dirk Mika , Christophe Pettus Cc: "pgsql-general@lists.postgresql.org" References: <7097609B-DCC8-49B8-932C-35A3D7D6A405@thebuild.com> <28EBE8BF-F6D7-4B75-BFBE-0B322610421E@mikatiming.de> From: Adrian Klaver Message-ID: <0865281f-d1f3-e87c-5526-5541ba83b924@aklaver.com> Date: Sat, 2 Jan 2021 07:36:21 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <28EBE8BF-F6D7-4B75-BFBE-0B322610421E@mikatiming.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 1/2/21 2:23 AM, Dirk Mika wrote: >>> 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: >>> >>> IF NOT UPDATING('IS_CANCELED') >>> THEN >>> :new.is_canceled := ...; >>> END IF; >>> >>> I have not found anything similar in PostgreSQL. What is the common approach to this problem? >> >> PostgreSQL doesn't have an exact equivalent. Typically, the OLD and NEW values are compared and then action is taken based on that. For example, in PL/pgSQL: >> >> IF NEW.is_canceled IS NOT DISTINCT FROM OLD.is_canceled THEN >> NEW.is_canceled := etc etc ; >> ENDIF; > > Unfortunately, this doesn't quite fit the logic I need. I don't need to know if the value was changed, but if the application that sent the UPDATE statement knows the column or not. > In our case, a number of different applications access the database, which may or may not know the column depending on the version. > And it is also regularly the case that SQL statements are executed directly in an SQL client by hand. And in the event that the column was not specified in these statements, a trigger is supposed to fill the value. > >> There's currently no way to detect if the column was simply not mentioned at all in the UPDATE statement. > > Hmm, that's odd. See thread below: https://www.postgresql.org/message-id/VisenaEmail.26.7cbf2947c8d23ceb.1769a2755ff%40tc7-visena > > BR > Dirk > > > > -- > Dirk Mika > Software Developer > > mika:timing GmbH > Strundepark - Kürtener Str. 11b > 51465 Bergisch Gladbach > Germany > > fon +49 2202 2401-1197 > dirk.mika@mikatiming.de > www.mikatiming.de > > AG Köln HRB 47509 * WEEE-Reg.-Nr. DE 90029884 > Geschäftsführer: Harald Mika, Jörg Mika > > -- Adrian Klaver adrian.klaver@aklaver.com