Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rule _RETURN question

Status
Not open for further replies.

dwhalen

Programmer
Feb 22, 2002
105
CA
Hello,

I am using 7.3 and I had to pg_dump a table and then change one of the fields to be able to store varchar(64) instead of 32. The problem came when I had to drop the table to load in the pg_dump.sql file. The table was referenced by a couple of views. So, I had to do a
DROP table tablename CASCADE.
Then postgres gave me these notices:
NOTICE: Drop cascades to rule _RETURN on view view_actor
NOTICE: Drop cascades to view view_actor
NOTICE: Drop cascades to rule _RETURN on view actor_list
NOTICE: Drop cascades to view actor_list

I know what to do about the views, I just have to recreate them. However, what are the rule _RETURNs ?? The problem is that where I work some things are documented and some are not :(
So, is the rule _RETURN just something to do with all views or am I going to have to ask every developer if they know what it is and just hope they remember making and have the code for it :[


Thanks for your help.

Later
 
What this means is that after creating the views, someone also created a RULE definition for each view. RULE is a non-standard SQL extension, but it is one of the coolest things about PostgreSQL. It's kind of like a trigger, only a more elegant solution for certain things. See
The idea here is that any table or view in the system can have a RULE, which allows you to "rewrite" the incoming query to do additional or alternate actions. The most common of these is to use a RULE to make a view updateable, which I am guessing is what your developers did.

Explanation: PostgreSQL views are not intrinsically updateable, but if you make a RULE that says 'ON UPDATE DO INSTEAD ...[update the two or more base tables in the view]', then the view effectively becomes updateable, or even insertable if you want, just like a regular table. A view can also be defined as ON SELECT (something most triggers can't do), so that, for example you could record an event in a log table everytime someone tries to view data in your main table. -------------------------------------------

My PostgreSQL FAQ --
 
Thanks for your reply.

I read the link that you gave me and I actually think that there was no rule created by another developer but rather, it seems Postgresql creates a rule automatically for views as you can see by this line from your link:
CREATE VIEW creates a dummy table (with no underlying storage) and associates an ON SELECT rule with it.

So I suppose when you drop a view postgresql will give a notice that a rule is being dropped as well, but that can be misleading. You may think that a rule was explicitly created when it wasn't, as in this case.

Thanks for you help

Later
 
Hmm... that may be true, but when I drop a view, it never gives me a notice about dropping the internal rule. I even tried DROP VIEW viewname CASCADE. Maybe it only happens when you cascade DROP from a base table. Or maybe you have some "verbose" option turned on. -------------------------------------------

My PostgreSQL FAQ --
 
As far as I know, any rules named as '_RETURN' is defined
by system when you create a view. So you don't need worry
about rules named '_RETURN'. As a fast check, you can
try to defined a rule named '_RETURN', postgresql will
issue an error message.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top