Re: Conditional INSERT - Mailing list pgsql-general

From Michael Lewis
Subject Re: Conditional INSERT
Date
Msg-id CAHOFxGr3WCD1Kb0mL8aXiRHyYpOaV98uzF_pcJA_ALF4V0qhjA@mail.gmail.com
Whole thread Raw
In response to Re: Conditional INSERT  (Michel Pelletier <pelletier.michel@gmail.com>)
Responses Re: Conditional INSERT
List pgsql-general
On Fri, Mar 15, 2019 at 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  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.

pgsql-general by date:

Previous
From: Michel Pelletier
Date:
Subject: Re: Conditional INSERT
Next
From: Paul Jungwirth
Date:
Subject: Re: Conditional INSERT