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 1hTYvf-0007nG-Cb for pgsql-general@arkaria.postgresql.org; Wed, 22 May 2019 21:37:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hTYvd-0006dk-TW for pgsql-general@arkaria.postgresql.org; Wed, 22 May 2019 21:37:41 +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 1hTYvd-0006dc-Jy for pgsql-general@lists.postgresql.org; Wed, 22 May 2019 21:37:41 +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 1hTYva-0005qK-W5 for pgsql-general@postgresql.org; Wed, 22 May 2019 21:37:41 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 97C4E20C69; Wed, 22 May 2019 17:37:37 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 22 May 2019 17:37:37 -0400 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=fm3; bh=y Q14DsckxIM0JeFwE6Pw3wBYRlZHsFl4GlVBl68YGkg=; b=Vcdhx4s8M+WI/Adjp fESPPJl9kLK5pKIoTtusJYnz/J4nmXf0mfnaJN2bdD4lQ+sL2eBMdRIYpp7LorNc meM1E4GmItR9u8MVcO0J3EeAi4i8/dxM4Eig7vCgX4Phk7p0fwf/DsE2y0RX6lDR vD86Rx3rwbWCVAxITwq9g2t6tcTGPusd0ZlJMsI4UWcS6kPfJxKZib6EWb8Pp4MC c0sdJHwqlDx9ae6aDn9LNh1jQrdKQ/IKPLHjr7b9sScM9Xv92mu/xvUhwQlf5Eaf eFDZJ/eECgx0PkfjE21y0huXTMD/iHWuF9xZavmKxT92f2lpKYgTtPl5orH4fi1G ljNhQ== 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=yQ14DsckxIM0JeFwE6Pw3wBYRlZHsFl4GlVBl68YG kg=; b=64Jh3iGvmDY1cEjiKaxoRmqKkVujWuNirT69TjZi29T9gT2st1CSuR2q0 1+oztKyKk0lYBb0lrmlsa2hZ0YUMST8QbuafgkaVxINDJsOOQUAMusjBDoXYXQBy P6de6mlbWUeKLa+/bgMLl4D+egpNzwfM+PtN7PEanCn2yxvArXn4z/XXOzI307FH X5q6/3m2XOr4hb6yAvH1OrMb9k93Gc0EI1i+d+51mLiClMtZrujFQhz/Gsf8uKVw FVqLnfGhtrEagAX+banHPIoAmKIqr1cIMtmZO2FqG7DuJY0KvgsNVw+XyMXZbNOs 9O3zFqPLr03igjR1Vj4ejxmN1nOYg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddruddufedgtddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtke ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuffhomhgrihhnpehpohhsthhgrhgvsh hqlhdqrghrtghhihhvvgdrohhrghdpphhoshhtghhrvghsqhhlrdhorhhgnecukfhppeej gedrleegrdejfedrvddvvdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrd hklhgrvhgvrhesrghklhgrvhgvrhdrtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from ranger.suse (unknown [74.94.73.222]) by mail.messagingengine.com (Postfix) with ESMTPA id 8BD5680061; Wed, 22 May 2019 17:37:36 -0400 (EDT) Subject: Re: Trigger bug ? To: PegoraroF10 , pgsql-general@postgresql.org References: <1558560792308-0.post@n3.nabble.com> From: Adrian Klaver Message-ID: Date: Wed, 22 May 2019 14:37:35 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <1558560792308-0.post@n3.nabble.com> 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 5/22/19 2:33 PM, PegoraroF10 wrote: > We created a usual trigger which seemed to be not firing or not working > properly. Then we put some raise notices on it and saw that it was returning > Null values. But why, it´s after insert and is a primary key, cannot be > null. https://www.postgresql.org/docs/11/plpgsql-trigger.html "The return value of a row-level trigger fired AFTER or a statement-level trigger fired BEFORE or AFTER is always ignored; it might as well be null. However, any of these types of triggers might still abort the entire operation by raising an error." More below. > > create function MyFunction() returns trigger as $$ > begin > raise '%', new.MyPK; > end$$ language plpgsql; > > create trigger MyTrigger after insert on MyTable execute procedure > MyFunction(); > > We forgot FOR EACH ROW/STATEMENT when created our trigger. > > On docs it´s written {ROW/STATEMENT} between {}, so it´s needed. But why did > it accepted our command to create that trigger ? https://www.postgresql.org/docs/11/sql-createtrigger.html "FOR EACH ROW FOR EACH STATEMENT This specifies whether the trigger function should be fired once for every row affected by the trigger event, or just once per SQL statement. If neither is specified, FOR EACH STATEMENT is the default. Constraint triggers can only be specified FOR EACH ROW. " > > > > -- > Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html > > -- Adrian Klaver adrian.klaver@aklaver.com