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 1l3NLs-0000Q6-Va for pgsql-general@arkaria.postgresql.org; Sat, 23 Jan 2021 18:09:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l3NLq-0007kS-Ts for pgsql-general@arkaria.postgresql.org; Sat, 23 Jan 2021 18:09:34 +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 1l3NLq-0007hV-7v for pgsql-general@lists.postgresql.org; Sat, 23 Jan 2021 18:09:34 +0000 Received: from stz-bg.com ([46.40.123.212] helo=mail.stzbg.com) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l3NLn-0007aI-BQ for pgsql-general@lists.postgresql.org; Sat, 23 Jan 2021 18:09:33 +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 9C6542E036D; Sat, 23 Jan 2021 20:09:25 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stz-bg.com; s=mail; t=1611425365; 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=plXFlvj5M9HQrJxKwZDQNC52F23FM/DJBi7w0wyg9FI=; b=Hw2JESwfGkTpPRcfmkrqK/oECocOJMhcU0Vbjb0M8bjKdY4UpHaOq4z7z7EllmcqkJQ4Kd kdIoDzqRdVCS5sLVwcaHrd+q6T4pPYIzxhCrgza/5hfWW6cJKG7jmSg4lfylGNNCU6cy25 DEB1ispndKNiUIq7BptsFFhrwNbxkYY= MIME-Version: 1.0 Date: Sat, 23 Jan 2021 20:09:23 +0200 From: Condor To: "David G. Johnston" Cc: pgsql-general@lists.postgresql.org Subject: Re: Need help with trigger In-Reply-To: References: <6feca05ea1521b0a4da87bfcfe78c39f@stz-bg.com> User-Agent: Roundcube Webmail/1.4.10 Message-ID: <7dcfcb8bfaed656fe17dd6c76fe7fb22@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 18:17, David G. Johnston wrote: > On Saturday, January 23, 2021, Condor wrote: > >> Hello ppl, >> >> I need help with trigger how to replace insert command with update. >> External program read data from one table and in every 30 min I need >> to refresh data in arhive table. >> What I want is: if data already inserted and end_date is not >> changed, only to update lastseen column. If data not exists to >> insert data and if data exists and end_date is changed >> to update end_date, lastseen and sendto columns. Well, update >> probably will never happened, this functionality is left for >> frontend but its can be cut off. > > Seems like an insert on conflict would be simpler. Otherwise, what is > your question or concern? > > David J. This was my first approach, but as the sample data I provide, end_date will always be updated not only if it is changed and my goal is to have no meaningless records. My question is there a way to update the trigger instead of inserting. HS