Re: Deprecating RULES

From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Josh Berkus <josh(at)agliodbs(dot)com>, Daniel Farina <daniel(at)heroku(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Deprecating RULES
Date: 2012-10-18 17:01:37
Message-ID: 508035F1.5080603@pinpointresearch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 10/17/2012 04:25 PM, Tom Lane wrote:
> ...Now having said that, I would definitely like to see rules in their
> current form go away eventually. But not without a substitute.
> Triggers are not a complete replacement, and no amount of wishful
> thinking makes them so.
...
> Perhaps it would be more profitable to try to identify the pain points
> that make people so eager to get rid of rules, and then see if we
> could alleviate them.

Alternately/additionally identify the deficiencies in triggers that
drive users to prefer rules. For example, a common need is to update a
log table whenever updates are made to a main table.

Using rules to accomplish this is very easy to understand and write,
even for most beginners. (Understand properly including limitations and
dangers is another issue, of course.) It is also easy to maintain. If
you drop the table, the rule is cleaned up as well.

With triggers you need to select from a variety of available languages,
write a function in that language and write a trigger that calls that
function. Dropping the function will remove the trigger but the user
must remember to delete the function as well, if desired. Nothing
insurmountable but inconvenient compared to the use of a rule.

Per the documentation "PostgreSQL only allows the execution of a
user-defined function for the triggered action. The standard allows the
execution of a number of other SQL commands..."

There may be valid reasons why implementing that part of the SQL
standard in PostgreSQL is difficult or unwise but removing that
limitation on triggers would eliminate one annoyance that pushes users
toward rules.

Cheers,
Steve

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Guillaume Lelarge 2012-10-18 17:08:53 Re: Bug in -c CLI option of pg_dump/pg_restore
Previous Message Daniel Farina 2012-10-18 16:56:05 Re: xlog filename formatting functions in recovery