TRIGGER or RULE for SELECT - Mailing list pgsql-hackers

From Melvin Davidson
Subject TRIGGER or RULE for SELECT
Date
Msg-id 5CA4D07E8D52ED4AB5499CA4E0898581146303C3F9@star2.corp.trenstar.net
Whole thread Raw
List pgsql-hackers
<div class="Section1"><p class="MsoNormal"><span style="font-family:"Arial","sans-serif"">Currently, there is a
limitationin PostgreSQL that any ON SELECT RULE</span><span style="font-family:"Arial","sans-serif""> must be an
unconditional<tt><span style="font-family:"Arial","sans-serif"">SELECT</span></tt> action that is <tt><span
style="font-family:"Arial","sans-serif"">INSTEAD.</span></tt></span><pclass="MsoNormal"><tt><span
style="font-family:"Arial","sans-serif""> </span></tt><pclass="MsoNormal"><tt><span
style="font-family:"Arial","sans-serif"">Thereasoning is “</span></tt><span
style="font-family:"Arial","sans-serif"">Thisrestriction was required to make rules safe enough to open them for
ordinaryusers, and it restricts <tt><span style="font-family:"Arial","sans-serif"">ON SELECT</span></tt> rules to act
likeviews.”</span><p class="MsoNormal"><tt><span style="font-family:"Arial","sans-serif""> </span></tt><pre><tt><span
style="font-size:11.0pt;font-family:"Arial","sans-serif"">Icannot understand the logic behind this, as RULES are
createdby DBA’s. Besides, going by that logic, a user could create a RULE like</span></tt></pre><pre><tt><span
style="font-size:11.0pt;font-family:"Arial","sans-serif""> </span></tt></pre><pre><tt><span
style="font-size:11.0pt;font-family:"Arial","sans-serif"">CREATERULE silly </span></tt><span
style="font-size:11.0pt;font-family:"Arial","sans-serif"">ASON <tt><i><span
style="font-family:"Arial","sans-serif"">SE</span></i></tt><tt><spanstyle="font-family:"Arial","sans-serif"">LECT
</span></tt></span></pre><pre><spanstyle="font-size:11.0pt;font-family:"Arial","sans-serif"">    TO <tt><span
style="font-family:"Arial","sans-serif"">table_a</span></tt>  DO INSTEAD  SELECT * FROM table_b.
</span></pre><pre><spanstyle="font-size:11.0pt;font-family:"Arial","sans-serif""> </span></pre><pre><span
style="font-size:11.0pt;font-family:"Arial","sans-serif"">Notto mention, an INSERT, UPDATE, or DELETE rule is
potentiallymuch more dangerous.</span></pre><pre><span style="font-size:11.0pt;font-family:"Arial","sans-serif"">eg: ON
INSERTDO INSTEAD SELECT function_to_delete();</span></pre><pre><span
style="font-size:11.0pt;font-family:"Arial","sans-serif""> </span></pre><pre><span
style="font-size:11.0pt;font-family:"Arial","sans-serif"">Isthat safe? </span><tt><span
style="font-size:11.0pt;font-family:"Arial","sans-serif"">Furthermore,it would be more beneficial to allow DO ALSO, so
thatan audit function could be invoked.  </span></tt></pre><pre><tt><span
style="font-size:11.0pt;font-family:"Arial","sans-serif""> </span></tt></pre><pre><tt><span
style="font-size:11.0pt;font-family:"Arial","sans-serif"">Likewise,the same applies to TRIGGERS. ON SELECT should also
bean option there for the same reason.</span></tt></pre><pre><tt><span
style="font-size:11.0pt;font-family:"Arial","sans-serif""> </span></tt></pre><pre><tt><span
style="font-size:11.0pt;font-family:"Arial","sans-serif"">Isthere some way that modifying the CREATE RULE for SELECT,
and/orTRIGGER could be presented to the developers?</span></tt></pre><pre><tt><span
style="font-size:11.0pt;font-family:"Arial","sans-serif""> </span></tt></pre><pre><tt><span
style="font-size:11.0pt;font-family:"Arial","sans-serif"">Thanksin advance,</span></tt></pre><pre><tt><span
style="font-size:11.0pt;font-family:"Arial","sans-serif"">MelvinDavidson.</span></tt></pre><p class="MsoNormal"><span
style="font-family:"Arial","sans-serif""> </span></div>

pgsql-hackers by date:

Previous
From: Tom Raney
Date:
Subject: Re: Plan targetlists in EXPLAIN output
Next
From: Decibel!
Date:
Subject: Re: Backend Stats Enhancement Request