Thread: multiple action rules

multiple action rules

From
Scott Marlowe
Date:
OK, so I'm trying to make a rule with >1 action.

The docs, not so helpfully, only seem to show a single action rule (at
least in the rules section, not sure about elsewhere)  The syntax
diagram:

CREATE RULE rule_name AS ON event
    TO object [WHERE rule_qualification]
    DO [INSTEAD] [action | (actions) | NOTHING];

seems to imply to me that >2 actions would look like this:

create rule audit_test as on delete to ntest do (
    insert into naudit(id,path) values (OLD.id, OLD.path);
    notify test;
)

But no matter what flavor of syntax I throw at this, I get:

syntax error at or near "insert" at character xxx

So, what's the magic pixie dust I need to sprinkle on this to make it
work?

Re: multiple action rules

From
Scott Marlowe
Date:
On Wed, 2005-06-22 at 18:31, Scott Marlowe wrote:
> OK, so I'm trying to make a rule with >1 action.
>
> The docs, not so helpfully, only seem to show a single action rule (at
> least in the rules section, not sure about elsewhere)  The syntax
> diagram:
>
> CREATE RULE rule_name AS ON event
>     TO object [WHERE rule_qualification]
>     DO [INSTEAD] [action | (actions) | NOTHING];
>
> seems to imply to me that >2 actions would look like this:
>
> create rule audit_test as on delete to ntest do (
>     insert into naudit(id,path) values (OLD.id, OLD.path);
>     notify test;
> )
>
> But no matter what flavor of syntax I throw at this, I get:
>
> syntax error at or near "insert" at character xxx
>
> So, what's the magic pixie dust I need to sprinkle on this to make it
> work?


Never mind, I finally figured it out...  About three minutes after
posting this.  sheesh.

Re: multiple action rules

From
Tom Lane
Date:
Scott Marlowe <smarlowe@g2switchworks.com> writes:
>> So, what's the magic pixie dust I need to sprinkle on this to make it
>> work?

> Never mind, I finally figured it out...  About three minutes after
> posting this.  sheesh.

If you think the docs are insufficiently clear, feel free to send in a
documentation patch.  Sometimes what seems obvious to the writer is less
so to readers ...

            regards, tom lane

Re: multiple action rules

From
Scott Marlowe
Date:
On Wed, 2005-06-22 at 19:49, Tom Lane wrote:
> Scott Marlowe <smarlowe@g2switchworks.com> writes:
> >> So, what's the magic pixie dust I need to sprinkle on this to make it
> >> work?
>
> > Never mind, I finally figured it out...  About three minutes after
> > posting this.  sheesh.
>
> If you think the docs are insufficiently clear, feel free to send in a
> documentation patch.  Sometimes what seems obvious to the writer is less
> so to readers ...

Well, what really gets me is that basically, the syntax diagram in
the psql environment has a syntax diagram that makes sense to me.

So I guess if there was a "patch" it would basically reference the syntax
rules given by psql \h create rule in the documentation.

But that makes me think that the syntax diagrams should probably be
abstracted out of the pure sgml realm, and grabbed by both psql and the
docs during build time.

OK, took a break and looked through the developer docs, and, yet again,
someone has done the exact thing I would have done, they've put the same
basic syntax diagram as "\h create rule" in the docs...

So, thanks again...

Re: multiple action rules

From
Tom Lane
Date:
Scott Marlowe <smarlowe@g2switchworks.com> writes:
> Well, what really gets me is that basically, the syntax diagram in
> the psql environment has a syntax diagram that makes sense to me.

> So I guess if there was a "patch" it would basically reference the syntax
> rules given by psql \h create rule in the documentation.

Hmm?  psql's \h output is mechanically extracted from the sgml docs.
Or are you looking at someplace other than the CREATE RULE reference
page?

            regards, tom lane

Re: multiple action rules

From
Scott Marlowe
Date:
On Wed, 2005-06-22 at 20:28, Tom Lane wrote:
> Scott Marlowe <smarlowe@g2switchworks.com> writes:
> > Well, what really gets me is that basically, the syntax diagram in
> > the psql environment has a syntax diagram that makes sense to me.
>
> > So I guess if there was a "patch" it would basically reference the syntax
> > rules given by psql \h create rule in the documentation.
>
> Hmm?  psql's \h output is mechanically extracted from the sgml docs.
> Or are you looking at someplace other than the CREATE RULE reference
> page?

I don't think you caught the end of my message.  I was looking at the
7.4 docs when I started writing, but by the end had gone to the
developer docs, where the change is already made.  So there's no need
for a patch for that.

Now I'm thinking I should make a patch for a demonstration of making a
rule with >1 action though...

Re: multiple action rules

From
Tom Lane
Date:
Scott Marlowe <smarlowe@g2switchworks.com> writes:
> Now I'm thinking I should make a patch for a demonstration of making a
> rule with >1 action though...

You're right, there are no such examples.  It would be interesting to
make a full-fledged demonstration of maintaining a join view (where
delete from the join means delete from both tables) --- in particular
the need to use an outer join so that the first table delete doesn't
cause rows to disappear from the view.

            regards, tom lane