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 1l3PIX-0006jR-8E for pgsql-general@arkaria.postgresql.org; Sat, 23 Jan 2021 20:14:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l3PIW-0004ue-5A for pgsql-general@arkaria.postgresql.org; Sat, 23 Jan 2021 20:14:16 +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 1l3PIV-0004uX-QU for pgsql-general@lists.postgresql.org; Sat, 23 Jan 2021 20:14:15 +0000 Received: from stz-bg.com ([46.40.123.212] helo=mail.stzbg.com) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l3PIT-0006B9-EJ for pgsql-general@lists.postgresql.org; Sat, 23 Jan 2021 20:14:15 +0000 Received: from www.stz-bg.com (stz-bg.com [IPv6:2a02:6800:0:99::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: condor@stz-bg.com) by mail.stzbg.com (Postfix) with ESMTPSA id 6FD192E0FA0; Sat, 23 Jan 2021 22:14:11 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stz-bg.com; s=mail; t=1611432851; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ssCQOwyWw+zhLYdv30ipAffCD1xBWIfdNxUeEj70ak4=; b=eC775b92Jj3+fKSAFmXGdWHzT/e/MX3NvpP7TQA0xnOUhVVlecFTIauXNwhK1+kSO0bHyh 4FgmTPyKOYIvD+8GrXTpvzPOqaEy78uifjjcRaDDGRW2FSKOMSlODvBRPGpDK2Egw46szX cB6HuxF+sqQXs0akSVLYT24EFWIhMWo= MIME-Version: 1.0 Date: Sat, 23 Jan 2021 22:14:09 +0200 From: Condor To: Adrian Klaver Cc: pgsql-general@lists.postgresql.org Subject: Re: Need help with trigger In-Reply-To: <3294def5-09f6-c384-d1fe-f5faf4bcf797@aklaver.com> References: <6feca05ea1521b0a4da87bfcfe78c39f@stz-bg.com> <62244d0f-03d7-6bed-cb7b-722ad32400ad@aklaver.com> <84864856b8ac6e5f35f68ace87c44556@stz-bg.com> <3294def5-09f6-c384-d1fe-f5faf4bcf797@aklaver.com> User-Agent: Roundcube Webmail/1.4.10 Message-ID: <533ed7d44063dca8b45626816aa51cad@stz-bg.com> X-Sender: condor@stz-bg.com Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 23-01-2021 20:49, Adrian Klaver wrote: > On 1/23/21 10:20 AM, Condor wrote: >> On 23-01-2021 18:31, Adrian Klaver wrote: >>> On 1/23/21 4:57 AM, Condor wrote: >>>> >>>> > >>> >>> So do an UPDATE and the RETURN NULL to cancel the INSERT. Untested >>> example: >>> >>> UPDATE arhive_table SET sendto = 0, uts = date_part('epoch', >>> CURRENT_TIMESTAMP)::integer WHERE contract = NEW.contract AND service >>> = NEW.service; >>> >>> RETURN NULL; >>> >> >> >> Yep, I think about this update and was my first approach but need to >> be done only if end_date is different. >> If end_date is the same this mean contract still exists so only update >> lastseen column, if the lastseen is not updated other process will >> read not seen contracts and will generate report and send them to >> delete services. If lastseen is changed and sendto is zero again, mean >> end_date is changed and need to be send new end_date again to other >> systems. > > So add an: > > ELSIF enddate = FROM NEW.end_date THEN > > and do UPDATE of lastseen column. > > Honestly I think this better handled by the external program that > doing the transformation. > >> >> >> Sorry, I'm sorry, I don't understand something. You mean to do pure INSERT ON CONFLICT DO or to modify the trigger ?