Webmut
Webmut

Reputation: 2868

RULE with multiple commands

I can't figure out how to specify multiple commands for a rule.
According to the documentation, the syntax for creating a rule is:

CREATE [ OR REPLACE ] RULE name AS ON event
TO table [ WHERE condition ]
DO [ ALSO | INSTEAD ] { NOTHING | command | ( command ; command ... ) }

As per this definition, I have tried to create the following rule:

CREATE TABLE "test" (
  "b" boolean NULL
);

-

CREATE OR REPLACE RULE test AS 
ON UPDATE TO test DO INSTEAD 
(
INSERT INTO test (b) SELECT FALSE;
INSERT INTO test (b) SELECT FALSE;
)

However, what happens is very weird - this query fails to parse the first insert complaining about syntax error at end of input LINE 4: INSERT INTO test (b) SELECT FALSE, but at the same time executes the rest of the query, therefore incorrectly creating a rule with just one insert command.

Notes: My version is 9.0 and I have not found a single example of a multi-command rule anywhere.

So, how do I correctly define multiple commands for a rule? Is it even possible?

Upvotes: 3

Views: 2593

Answers (1)

Webmut
Webmut

Reputation: 2868

As per comments, the problem lies in the database management tool I used - Adminer.
It somehow slices/corrupts the query, so you cannot create more than one command in a rule.

Note that this bug is present even in the (as of now) latest version 3.7.1.

Thanks a_horse_with_no_name for helping me resolve this issue.

Upvotes: 2

Related Questions