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 1h4s2y-0003Dy-QP for pgsql-general@arkaria.postgresql.org; Fri, 15 Mar 2019 18:59:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h4s2w-0005Dq-AJ for pgsql-general@arkaria.postgresql.org; Fri, 15 Mar 2019 18:59:10 +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 1h4s2u-0005Dj-QC for pgsql-general@lists.postgresql.org; Fri, 15 Mar 2019 18:59:10 +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 1h4s2r-00081b-1K for pgsql-general@lists.postgresql.org; Fri, 15 Mar 2019 18:59:08 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 66DAC21CE7; Fri, 15 Mar 2019 14:59:03 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Fri, 15 Mar 2019 14:59:03 -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=fm2; bh=v xdisc1F8PR/72Tl7dNY1jZUuayQ5qYUmEwmNJB+z1g=; b=B8Rzs+h+gE2PZKFoQ O912VozGo1aptUMCCYR2Bf9UJRAYIvIEUDf44mH8bT1HNPC7tAgWClVTtb5gflFW FpGxaMW9IoqVSVpgdWkw751BOzcXT1KuZHalGLGVbUwEAVjJL7Ov2CgrwXluoSTn JUSaK+MM4rz/1xZp3lfM8nJ+r4GekbuRPcbu2tavkJc0G0moe5fW+ZtjnmDQ28Kz etpsa8S7fioVNtmyyuWwb9PwVG8WFrc1xxIomHY4/o40vGI+T9O2CXmbxYk+sqgf jwEINWSz2U//HT74W1wswkadaZXwLHdLpUyr6ofX3fdGIGTaPHFnDk30mlDfOLSd PQOeg== 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=vxdisc1F8PR/72Tl7dNY1jZUuayQ5qYUmEwmNJB+z 1g=; b=GqN5InFAtIA59vL5rtIgS4FQGp4w8mBBShZyayo7RYrnqIQNFEWJlUGV7 6/ouKXc+pwflrjOi+M4Kh57wcmY6pAw1tDW7Zb7CWz7FCh/BQfgTNYP094sV9Pq4 3epyGeBeii2stwP4jtC4vrGlPyPEjgvNM6g+MCu9CC0PUNtmQ60d8hKBLWKmtsCR tVQUU9S7Yp7QHFXb1tpLbrju0g4zTXil7okVCyAN+VA/PoXc0w0aR2fAEFyKQFhQ 7oySO/8Kn9FlU9fx+dmBkI/XPr4DFWe7k1fxj20ZvX4BM5E44ReMVVbJlGRPZoS/ WOLZZf0jdpIGn0g1/YFrDy+ChUlaw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrheehgdduvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtke ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecukfhppeejuddrvdduvddrudehtddrvd dtvdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghk lhgrvhgvrhdrtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from [192.168.1.4] (unknown [71.212.150.202]) by mail.messagingengine.com (Postfix) with ESMTPA id 2C68510288; Fri, 15 Mar 2019 14:59:02 -0400 (EDT) Subject: Re: Conditional INSERT To: basti , pgsql-general@lists.postgresql.org References: <68951fae-3281-c9ad-09b7-205e0bb1c5ae@unix-solution.de> <1ebb57da-c34b-6581-ea33-bdf78f6990f8@unix-solution.de> From: Adrian Klaver Message-ID: <53dc55ae-506f-2aed-ea80-50f0978837ab@aklaver.com> Date: Fri, 15 Mar 2019 11:59:01 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <1ebb57da-c34b-6581-ea33-bdf78f6990f8@unix-solution.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 3/15/19 11:54 AM, basti wrote: > this is a dns database, and the client is update the _acme-challenge for > LE certificates. I don't want that the client can insert "any" txt record. > the client should only insert data if the hostname start with > _acme-challenge. i have no control on client. > > i have try this rule but the server reject this with a endless loop: To borrow a quote: "I had a problem so I decided to use a rule, now I have two problems." Do not use a rule. As suggested upstream use a BEFORE INSERT trigger, you will be a lot happier. > > CREATE RULE insert_acme AS ON INSERT TO t_dnsadmin_records_txt > WHERE NEW.hostname like '_acme-challenge%' > DO INSERT INTO t_dnsadmin_records_txt VALUES ( > NEW.domainid, > NEW.hostname, > NEW.txtdata > ); > > > On 15.03.19 19:17, Michael Lewis wrote: >> On Fri, Mar 15, 2019 at 10:55 AM basti > > wrote: >> >> Hello, >> >> I want to insert data into table only if condition is true. >> For example: >> >> INSERT into  mytable (domainid, hostname, txtdata) >>   VALUES (100,'_acme.challenge.example', 'somedata'); >> >> >> Alternative to a trigger implementation, if you are generating that >> INSERT statement, you can change it to use a sub-select or CTE that >> contains no values if the domainid isn't what you like. If you want it >> to fail with error, you could add a check constraint. We might need more >> context on what you are doing and why to give good advice. > > -- Adrian Klaver adrian.klaver@aklaver.com