Re: Conditional INSERT

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ken Tanzer <ken(dot)tanzer(at)gmail(dot)com>
Cc: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, basti <mailinglist(at)unix-solution(dot)de>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Conditional INSERT
Date: 2019-03-16 01:43:06
Message-ID: 21578.1552700586@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ken Tanzer <ken(dot)tanzer(at)gmail(dot)com> writes:
> OK, and thanks for the info. I've gleaned that rules are not "deprecated"
> in the sense that they are slated for removal, but they are rather
> discouraged. Since that's the case, wouldn't it make sense to warn users
> about this?

There's no plan to remove them, but we do encourage people to think of
triggers first. That's why the triggers chapter appears first, and why
the "rules vs. triggers" section doesn't really read as evenhanded
(to me anyway).

> In the section on "Rules vs. Triggers" (41.7), it doesn't even hint at
> this, and even says:
> *"For the things that can be implemented by both, which is best depends on
> the usage of the database."*

You're ignoring the sentence immediately before that, which is

Writing such triggers is often easier than writing rules, particularly
if complex logic is required to perform the update.

as well as the one at the end of its (short) paragraph:

However, the trigger approach is conceptually far simpler than the
rule approach, and is easier for novices to get right.

The only case where we're really encouraging people to use rules is
where the overhead of a trigger is unacceptable. Even then, this
whole section is written thinking of per-row triggers. The performance
tradeoffs would likely be quite different if using a per-statement trigger
with transition tables. But that's a very new feature, and I don't think
anyone's done serious performance comparisons of that vs. rules.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Steve Haresnape 2019-03-16 08:53:33 Fwd: Camel case identifiers and folding
Previous Message Ron 2019-03-16 01:02:21 Re: Permission Read Only User