concept rule in category postgis

appears as: rules, rule, The rule
PostGIS in Action, Third Edition

This is an excerpt from Manning's book PostGIS in Action, Third Edition.

The rules table is a table of rules where each row contains an ID and a rule. The ID is just a number. The rule is a sequence of numbers that denote tokens and separators. For more details about what the token numbers correspond to and how rules are set up, refer to the “Address Standardizer Rules Table structure” section in the PostGIS Manual (postgis.net/docs/rulestab.html).

You can create an alternate set of rules, gaz, and lex tables to suit your needs and pass the table names in as inputs to the standardizer. This will allow you to switch between conventional address geocoding and oddballs like the grid-style addresses found in Utah and alphanumeric addresses found in Wisconsin.

Similarly, you can delete from the view without writing any triggers or rules.

DELETE FROM ch14.subways WHERE feature_name = 'subway 1';

Although you can also insert into the view, for this particular example we’re not exposing the feature_type, so the insert would never result in a record that satisfies the filter condition. In order to guarantee that all new records are tagged with feature_type = 'subway', you’ll need to use a rule or trigger.

14.5 Using Triggers and rules

Sophisticated RDBMSs usually offer ways to catch the execution of certain SQL commands on a table or view and allow some form of conditional processing to take place in response to these events. PostgreSQL is certainly not devoid of such features and can perform additional processing when it encounters the four core SQL commands: SELECT, UPDATE, INSERT, and DELETE. The two mechanisms for handling this conditional processing are triggers AND rules.

Rules are instructions for how to rewrite a query. They don’t directly change data, they just rewrite the instructions to change data.

Though PostgreSQL has supported rules too far back to remember and much of the logic of views is under the hood implemented with rules, you should avoid their direct use because the direct use of the rule feature may be disabled in a future version of PostgreSQL. The advent of ability to apply INSTEAD OF triggers on views has made the direct use of rules more or less obsolete. As such this chapter will not cover the use of rules. Triggers on the other hand have the following benefits over rules.