Rules, Select, Union - Mailing list pgsql-sql

From Itai Zukerman
Subject Rules, Select, Union
Date
Msg-id 87d7jmrmmu.fsf@matt.w80.math-hat.com
Whole thread Raw
Responses Re: Rules, Select, Union  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
I'm doing this:
 CREATE TABLE data ( val int4 ); CREATE TABLE pos ( ) INHERITS ( data ); CREATE TABLE neg ( ) INHERITS ( data );
 CREATE RULE data_to_pos AS ON INSERT TO data WHERE NEW.val > 0 DO INSTEAD   INSERT INTO pos ( val ) VALUES ( NEW.val
);
 CREATE RULE data_to_neg AS ON INSERT TO data WHERE NEW.val < 0 DO INSTEAD   INSERT INTO neg ( val ) VALUES ( NEW.val
);

So far, I think, so good.  (Though, sometimes it looks like the second
rule is never triggered even though val < 0.  The real application
that this simple example comes from has a bunch of triggers, though,
so it could be some weird interaction...)  Now I want to do:
 CREATE RULE data_val AS ON SELECT TO data DO INSTEAD   SELECT * FROM pos   UNION   SELECT * FROM neg;

Can this be done?  I'm not having much success...

This is 7.0.2...

-itai


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Database in recovery mode
Next
From: Tom Lane
Date:
Subject: Re: Rules, Select, Union