From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Ken Tanzer <ken.tanzer@gmail.com>
Cc: basti <mailinglist@unix-solution.de>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Conditional INSERT
Date: Fri, 15 Mar 2019 16:42:25 -0700
Message-ID: <b6316de2-1072-0724-7149-7e0ea4feaaf9@aklaver.com> (raw)
In-Reply-To: <CAD3a31U5YB8vd4CyKWrbuZoqgiE58SCdOUck6ju9b_yvrZ9Daw@mail.gmail.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>
<CAD3a31U5YB8vd4CyKWrbuZoqgiE58SCdOUck6ju9b_yvrZ9Daw@mail.gmail.com>
On 3/15/19 4:23 PM, Ken Tanzer wrote:
> On Fri, Mar 15, 2019 at 11:59 AM Adrian Klaver
> <adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>> wrote:
>
> 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
> > );
> >
> >
>
>
> Just curious, but wanted to follow up on whether rules are
> across-the-board discouraged? I've seen disparaging comments about
> them, but I don't see any indication of that on the create rule page.
See here:
https://www.postgresql-archive.org/Deprecating-RULES-td5727689.html
The rumor crops periodically that they will be deprecated. I personally
do not see that happening any time soon.
My issue with rules is this:
https://www.postgresql.org/docs/11/rules.html
If you can understand what really goes on in the above you are ahead of
me. Given that my experience is that they do the unexpected as often as
the expected so I stay away from them. Triggers I understand even when
they error, which is the important part.
>
> The other suggestion in this thread--a foreign key--will throw an
> error. Your suggestion of a before trigger might well be better (and if
> so, why?), but is there anything particularly wrong or bad about using a
> rule that would actually work? Something along these lines:
The trouble is simple rarely stays simple and following logic is a lot
easier in a trigger function then a rule. This is down mostly to the
query rewrite that goes on in a rule. That is border line, if not
outright, black magic. Try to follow what happens here:
https://www.postgresql.org/docs/11/rules-update.html
41.4.1.1. A First Rule Step by Step
>
> CREATE RULE insert_acme AS ON INSERT TO t_dnsadmin_records_txt
> WHERE NOT NEW.hostname like '_acme-challenge%'
> DO INSTEAD NOTHING;
>
> Thanks,
> Ken
>
>
>
> --
> AGENCY Software
> A Free Software data system
> By and for non-profits
> /http://agency-software.org//
> /https://demo.agency-software.org/client/
> ken.tanzer@agency-software.org <mailto:ken.tanzer@agency-software.org>
> (253) 245-3801
>
> Subscribe to the mailing list
> <mailto:agency-general-request@lists.sourceforge.net?body=subscribe> to
> learn more about AGENCY or
> follow the discussion.
--
Adrian Klaver
adrian.klaver@aklaver.com
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, ken.tanzer@gmail.com, mailinglist@unix-solution.de
Subject: Re: Conditional INSERT
In-Reply-To: <b6316de2-1072-0724-7149-7e0ea4feaaf9@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> <CAD3a31U5YB8vd4CyKWrbuZoqgiE58SCdOUck6ju9b_yvrZ9Daw@mail.gmail.com> <b6316de2-1072-0724-7149-7e0ea4feaaf9@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