pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: basti <mailinglist@unix-solution.de>
To: pgsql-general@lists.postgresql.org
Subject: Re: Conditional INSERT
Date: Fri, 15 Mar 2019 11:59:01 -0700
Message-ID: <53dc55ae-506f-2aed-ea80-50f0978837ab@aklaver.com> (raw)
In-Reply-To: <1ebb57da-c34b-6581-ea33-bdf78f6990f8@unix-solution.de>
References: <68951fae-3281-c9ad-09b7-205e0bb1c5ae@unix-solution.de>
	<CACxu=vKcVZdjsmMQyGf2tAcVAt8vyz2X1b+ynPb=_==AATjbVA@mail.gmail.com>
	<CAHOFxGr3WCD1Kb0mL8aXiRHyYpOaV98uzF_pcJA_ALF4V0qhjA@mail.gmail.com>
	<1ebb57da-c34b-6581-ea33-bdf78f6990f8@unix-solution.de>

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 <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.
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com




view thread (36+ messages)  latest in thread

Message-ID: <53dc55ae-506f-2aed-ea80-50f0978837ab@aklaver.com>
Permalink:  ../53dc55ae-506f-2aed-ea80-50f0978837ab@aklaver.com/
Also on:    postgresql.org/message-id/53dc55ae-506f-2aed-ea80-50f0978837ab@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, mailinglist@unix-solution.de
  Subject: Re: Conditional INSERT
  In-Reply-To: <53dc55ae-506f-2aed-ea80-50f0978837ab@aklaver.com>
  References: <68951fae-3281-c9ad-09b7-205e0bb1c5ae@unix-solution.de> <CACxu=vKcVZdjsmMQyGf2tAcVAt8vyz2X1b+ynPb=_==AATjbVA@mail.gmail.com> <CAHOFxGr3WCD1Kb0mL8aXiRHyYpOaV98uzF_pcJA_ALF4V0qhjA@mail.gmail.com> <1ebb57da-c34b-6581-ea33-bdf78f6990f8@unix-solution.de> <53dc55ae-506f-2aed-ea80-50f0978837ab@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox