Multiple rules on the same table and same event type are applied in alphabetical name order. This must be distinct from the name of any other rule for the same table. (This method does not currently work to support RETURNING queries, however.) Then make the conditional rules non- INSTEAD in the cases where they are applied, they add to the default INSTEAD NOTHING action. If you want to handle all the useful cases in conditional rules, add an unconditional DO INSTEAD NOTHING rule to ensure that the system understands it will never be called on to update the dummy table. If the rule is conditional, or is not INSTEAD, then the system will still reject attempts to perform the update action, because it thinks it might end up trying to perform the action on the dummy table of the view in some cases. There is a catch if you try to use conditional rules for complex view updates: there must be an unconditional INSTEAD rule for each action you wish to allow on the view. If you want to support INSERT RETURNING and so on, then be sure to put a suitable RETURNING clause into each of these rules. You can create the illusion of an updatable view by defining ON INSERT, ON UPDATE, and ON DELETE rules (or any subset of those that's sufficient for your purposes) to replace update actions on the view with appropriate updates on other tables. It is considered better style to write a CREATE VIEW command than to create a real table and define an ON SELECT rule for it. Thus, an ON SELECT rule effectively turns the table into a view, whose visible contents are the rows returned by the rule's SELECT command rather than whatever had been stored in the table (if anything). Presently, ON SELECT rules must be unconditional INSTEAD rules and must have actions that consist of a single SELECT command. More information about the rules system is in Chapter 41. If you actually want an operation that fires independently for each physical row, you probably want to use a trigger, not a rule. The transformation happens before the execution of the command starts. It is important to realize that a rule is really a command transformation mechanism, or command macro. Rules are used to implement SQL views as well. Alternatively, an INSTEAD rule can replace a given command by another, or cause a command not to be executed at all. Roughly speaking, a rule causes additional commands to be executed when a given command on a given table is executed. The PostgreSQL rule system allows one to define an alternative action to be performed on insertions, updates, or deletions in database tables. CREATE OR REPLACE RULE will either create a new rule, or replace an existing rule of the same name for the same table. CREATE RULE defines a new rule applying to a specified table or view.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |