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 1h4rP4-0001Xy-Ui for pgsql-general@arkaria.postgresql.org; Fri, 15 Mar 2019 18:17:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h4rP2-0001Go-T2 for pgsql-general@arkaria.postgresql.org; Fri, 15 Mar 2019 18:17:56 +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 1h4rP2-0001EQ-GX for pgsql-general@lists.postgresql.org; Fri, 15 Mar 2019 18:17:56 +0000 Received: from mail-yw1-xc35.google.com ([2607:f8b0:4864:20::c35]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h4rOt-00070C-M3 for pgsql-general@postgresql.org; Fri, 15 Mar 2019 18:17:55 +0000 Received: by mail-yw1-xc35.google.com with SMTP id x129so8016865ywc.1 for ; Fri, 15 Mar 2019 11:17:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=entrata-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hilNHTNpO7GQ4KBLqNFoMZZ6j0uLpJPCoxaaeeStxV8=; b=urfY1qclKxursnvYGVqp6w+uAJh0fgCzs5K5UxnGuVnOV25nzZfzs/W6KQQ0yztXBn rHTnNRNGKtwa09M30FfvetHK/CxQJ62ZGC4LwMtgAzfZuWLCnsZZJxWs+g1TlGjHmAM/ tYLXmHWhr4W2/yLOzThbfxZckZU+4w8/m9JAgnt1j+Z6KncZdf35xDyG276DqyhVXntw K/awindaMEK+q/Tk2/paPudAy2UCVSwL1Xkkn5C4LLnH7xu8KzkPe4ZoVEBznv/ST23x S2zXv4R/9PCrj4TLiXCz5HLGn4z8AWzN16OjflXoe6OqnaL8yKVvd8IiN4tIyAZUaEoa awtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hilNHTNpO7GQ4KBLqNFoMZZ6j0uLpJPCoxaaeeStxV8=; b=nZ8VKu4iLy7XJV6NCL+yguIYcJK9rk/mpxqWlnMcH0KCaqay8Nxz8eGa9Harc1JIxe 0wOtLAIVM1GhlCyq0UOAYkNzL/3YpyrjH36/xUK/s90GYOa6VS2b80ot/lgiuLE/2qNs HTvtsgL02ijhAU6lLXrLf3g6KThPE8CzYArPiIWr0KSo8S1TSB/0NqEG5j3ZJv5sd96E nI+LBqQeBEgoeEmN8ECiZyJEuaIalBz7VE0F4yyLuLF0gLmYi/O7flzRuqCQ9OG78HMV 122RM0zSKS9cKSeucajF+ej9NBlvqG7Dsc7NGvgzxYaxtsFfbj4KfyDqG6/G9bxpeiAw YvlA== X-Gm-Message-State: APjAAAUYGKqym3A6fm9n6DIa6ssS7CRvLZ7UNlCCdH7KX+c7SwFkolhh cftpDlp8WHz2cELEVbqMHzkmqZCx8MVx+6Z36zLrdfyQKnMr3w== X-Google-Smtp-Source: APXvYqzGDh19J/YnZAE+/GWt9mF7sWba94k2ICXNzl4DivlyjXy9fswSDLrMJ9Xf8iPbemglcoUfjcyYlQ5g5lbOtFM= X-Received: by 2002:a25:d64e:: with SMTP id n75mr4158361ybg.199.1552673864741; Fri, 15 Mar 2019 11:17:44 -0700 (PDT) MIME-Version: 1.0 References: <68951fae-3281-c9ad-09b7-205e0bb1c5ae@unix-solution.de> In-Reply-To: From: Michael Lewis Date: Fri, 15 Mar 2019 12:17:17 -0600 Message-ID: Subject: Re: Conditional INSERT To: Michel Pelletier Cc: basti , Postgres General Content-Type: multipart/alternative; boundary="000000000000290c910584260e38" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --000000000000290c910584260e38 Content-Type: text/plain; charset="UTF-8" > > 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. --000000000000290c910584260e38 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Fri, Mar 15, 2019 a= t 10:55 AM basti <mailinglist@unix-solution.de> wrote:
Hello,
I want to insert data into table only if condition is true.
For example:

INSERT into=C2=A0 mytable (domainid, hostname, txtdata)
=C2=A0 VALUES (100,'_acme.challenge.example', 'somedata');<= br>
=C2=A0
Alternative to a t= rigger 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 domain= id isn't what you like. If you want it to fail with error, you could ad= d a check constraint. We might need more context on what you are doing and = why to give good advice.
--000000000000290c910584260e38--