Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gyO28-0006ae-7w for pgsql-general@arkaria.postgresql.org; Mon, 25 Feb 2019 21:43:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gyO26-0008LX-Pz for pgsql-general@arkaria.postgresql.org; Mon, 25 Feb 2019 21:43:30 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gyO0h-0002Lt-CR for pgsql-general@lists.postgresql.org; Mon, 25 Feb 2019 21:42:03 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gyO0d-0002Ug-TF for pgsql-general@lists.postgresql.org; Mon, 25 Feb 2019 21:42:02 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 7648E231EF; Mon, 25 Feb 2019 16:41:58 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 25 Feb 2019 16:41:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=q uGd/JghkHs6k8rmLxsHMnA/zzveb5Ljh6m8gU0/NO0=; b=bZuTrOHuKcvCneWqo HX5lIVxudgNIpn/n+yFJqinPsBq/dKJ/WAYkonmzUFZgkbIWI1gAnYbF4HMooSsc /mXsIj3NW0Zzz8+me5UxRcSsKRXJaiuq2bvn81hLarsYry3mJF8QEhNW8FFw5Sj8 jrGl+0SnqqECAznHgzVIuJLiC+9TTLJ8INtp1TMk6eHkSMMjxNQSj59GHu4ytwV3 aee0H9tMLiJx/O9GU1v7EXpI36XOfKTHHH/mq1Dt+ntazhCNDxU5duhalQCnvbCk iYdDk8vlTSRN0a3lQDl45mK8lBHsCiw8nkvRJsPmj/HjqvznAeTLq0YZdemfSNPa Pnfsw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=fm2; bh=quGd/JghkHs6k8rmLxsHMnA/zzveb5Ljh6m8gU0/N O0=; b=t4dDkR91IZhDRoeMU+4DbBIYBmaQe8un4s2lLndI83gJVSMHwxEoRwT/a KG4DNO3gkgs3gPF/kGDhBXgaUr3oTo1uQXCZ8J4NI5Z1vUs934s3EM2xOvc1IEte lh3OPa653pO4s/EBRFJBhkNNlq9AFI2M5sTPWFYYV2eaS0KnClaVjxPXdKRx407A qKAqfsbsqa97hBkxwTXj5QrIZOAsrTYIYWhS0n4BDkg87rE5qsnYX/SxlfPsBTfg 2jZ1qu7OOZsw+FlY2d8tsaW2KnIK6+PnCbztDm3MslNwrQgt9IvA+1eObXuspEFU nZjspSZUCrrCWzez/HKjm1lFG9Cuw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrudejgdduheegucdltddurdegtdelrddttd dmucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfquhht necuuegrihhlohhuthemuceftddtnecunecujfgurhepuffvfhfhkffffgggjggtgfesth ekredttdefjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdr khhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenucffohhmrghinhepfigrmhgsrggthh gvrhhsqdhoshhmrdifvggsshhithgvnecukfhppeejgedrleegrdejfedrvddvvdenucfr rghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrh drtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from ranger.suse (unknown [74.94.73.222]) by mail.messagingengine.com (Postfix) with ESMTPA id 63AEA10336; Mon, 25 Feb 2019 16:41:57 -0500 (EST) Subject: Re: update table with suppress_redundant_updates_trigger() To: wambacher@posteo.de, pgsql-general@lists.postgresql.org References: From: Adrian Klaver Message-ID: Date: Mon, 25 Feb 2019 13:41:56 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: 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 2/25/19 10:42 AM, wambacher@posteo.de wrote: > Hi, > > i'm doing a lot of updates in my database, but most of them are not > necessary at all (sorry, just detected it) Would it not be easier to just not do the unnecessary updates? Or to put it another way what distinguishes necessary/unnecessary? > > Therefore i installed a trigger to minimize real updates. > > create trigger suppress_redundant_updates_boundaries >    before update on boundaries >    for each row execute procedure suppress_redundant_updates_trigger(); > > Is there a way to get the count of the real table updates? > > Using pl/pgsql i'm updating boundaries  with > >                   update boundaries >                      set id             = bT2.id, >                          country        = bT2.country, >                          type           = 'admin', >                          value          = bT2.value, > ... >                         ,qm             = bT2.qm >                         ,lwqm           = > st_area(geography(coalesce(xlandarea,rT.way))) >                    where id = bT2.id; > >                    if (found) then >                       if (debug > 0) then raise notice 'real db update > of % done 2', bT2.id; end if; >                       updatedDB := updatedDB + 1; >                    end if; > > i get a "wrong" result, because "found" is always true, even when the > records are identical (hope so) and an update should be suppressed by > the trigger. > > Question: will "found" be set when update has been blocked by the > trigger - or does that not matter? > > if "found" is always true: what else can i do? Untested: IF NEW.* != OLD.* THEN RETURN NEW.* ELSE RETURN NULL END IF; > > regards > > walter > > -- > My projects: > > Admin Boundaries of the World > Missing Boundaries > > Emergency Map > Postal Code Map (Germany only) > Fools (QA for zipcodes in Germany) > Postcode Boundaries of Germany -- Adrian Klaver adrian.klaver@aklaver.com