Re: Conditional INSERT - Mailing list pgsql-general

From basti
Subject Re: Conditional INSERT
Date
Msg-id 1ebb57da-c34b-6581-ea33-bdf78f6990f8@unix-solution.de
Whole thread Raw
In response to Re: Conditional INSERT  (Michael Lewis <mlewis@entrata.com>)
Responses Re: Conditional INSERT  (Adrian Klaver <adrian.klaver@aklaver.com>)
List pgsql-general
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:

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 <mailinglist@unix-solution.de
>     <mailto: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: Paul Jungwirth
Date:
Subject: Re: Conditional INSERT
Next
From: Adrian Klaver
Date:
Subject: Re: Conditional INSERT