rules problem

Started by Georgi Chorbadzhiyskiabout 23 years ago4 messagesgeneral
Jump to latest

Hi, I have strange problem with rules. It looks like when multiple rows
are affected, the rule is executed only for the first row.
Is this expected behaviour? Please someone hit me with a cluebat :)

Please try the attached two tests to see what I mean.
The tests are for pgsql-7.2 if you want to try them on 7.3 after
DROP TABLE xxx add CASCADE, and remove DROP RULE xxx lines.

Here's what I see:

*** First test ***
DROP
CREATE
DROP
CREATE
ERROR: Rule or view "add_to_data" not found
CREATE
ERROR: Rule or view "del_from_data" not found
CREATE
INSERT 357883308 1
INSERT 357883309 1
INSERT 357883310 1
INSERT 357883311 1
INSERT 357883312 1
id | data_counters | expected
----+---------------+------------------------------
1 | 4 | data_counters should be == 4
(1 row)

DELETE 4
id | data_counters | expected
----+---------------+------------------------------------
1 | 3 | data_counters should be == 0 NOT 3
(1 row)

*** Second test ***
DROP
CREATE
DROP
CREATE
ERROR: Rule or view "add_to_data" not found
CREATE
ERROR: Rule or view "del_from_data" not found
CREATE
INSERT 357886505 1
INSERT 357886506 1
INSERT 357886507 1
INSERT 357886508 1
INSERT 357886509 1
id | data_counters | expected
----+---------------+------------------------------
1 | 4 | data_counters should be == 4
(1 row)

DELETE 1
DELETE 1
DELETE 1
DELETE 1
id | data_counters | expected
----+---------------+------------------------------
1 | 0 | data_counters should be == 0
(1 row)

--
Georgi Chorbadzhiyski
http://georgi.unixsol.org/

Attachments:

boza-7.2-t1.sql.txttext/plain; name=boza-7.2-t1.sql.txtDownload
boza-7.2-t2.sql.txttext/plain; name=boza-7.2-t2.sql.txtDownload
#2Joshua Moore-Oliva
josh@chatgris.com
In reply to: Georgi Chorbadzhiyski (#1)
Re: rules problem

Usually it's a good idea to get rid of errors?

Hope you got the big foam HOS on :)

Josh.

Show quoted text

On March 21, 2003 05:18 am, Georgi Chorbadzhiyski wrote:

Hi, I have strange problem with rules. It looks like when multiple rows
are affected, the rule is executed only for the first row.
Is this expected behaviour? Please someone hit me with a cluebat :)

Please try the attached two tests to see what I mean.
The tests are for pgsql-7.2 if you want to try them on 7.3 after
DROP TABLE xxx add CASCADE, and remove DROP RULE xxx lines.

Here's what I see:

*** First test ***
DROP
CREATE
DROP
CREATE
ERROR: Rule or view "add_to_data" not found
CREATE
ERROR: Rule or view "del_from_data" not found
CREATE
INSERT 357883308 1
INSERT 357883309 1
INSERT 357883310 1
INSERT 357883311 1
INSERT 357883312 1
id | data_counters | expected
----+---------------+------------------------------
1 | 4 | data_counters should be == 4
(1 row)

DELETE 4
id | data_counters | expected
----+---------------+------------------------------------
1 | 3 | data_counters should be == 0 NOT 3
(1 row)

*** Second test ***
DROP
CREATE
DROP
CREATE
ERROR: Rule or view "add_to_data" not found
CREATE
ERROR: Rule or view "del_from_data" not found
CREATE
INSERT 357886505 1
INSERT 357886506 1
INSERT 357886507 1
INSERT 357886508 1
INSERT 357886509 1
id | data_counters | expected
----+---------------+------------------------------
1 | 4 | data_counters should be == 4
(1 row)

DELETE 1
DELETE 1
DELETE 1
DELETE 1
id | data_counters | expected
----+---------------+------------------------------
1 | 0 | data_counters should be == 0
(1 row)

In reply to: Joshua Moore-Oliva (#2)
Re: rules problem

Joshua Moore-Oliva wrote:

Usually it's a good idea to get rid of errors?

The errors are not the problem. They're shown because of the
DROP statements.

--
Georgi Chorbadzhiyski
http://georgi.unixsol.org/

#4Doug McNaught
doug@mcnaught.org
In reply to: Georgi Chorbadzhiyski (#1)
Re: rules problem

Georgi Chorbadzhiyski <gf@unixsol.org> writes:

Hi, I have strange problem with rules. It looks like when multiple rows
are affected, the rule is executed only for the first row.
Is this expected behaviour? Please someone hit me with a cluebat :)

Rules are not triggers. They are rewritings of the query into a
different form.

It looks like you want a trigger.

-Doug