Introduction to PostgreSQL Rules - Making entries which can't be altered

From PostgreSQL wiki

Introduction

Have you tried out PostgreSQLs' "RULES" yet? If you haven't you're probably going to like this quick and practical introduction which you could find yourself using straight away!

PostgreSQL Rules' are used to intercept and change a query before it's executed. For example, lets say you have a table people can add stuff to, but you need to put 3 entries in the table which can never be changed or removed. This is how you do it :

The "nothing" clause is a legitimate PostgreSQL Rule clause, effectively removing the actions where the SQL query would have updated any of the first 3 entries in this gift_certificates table. Still, all the SQL queries which are run on this table will work perfectly (except those attempting to update or delete any of these first 3 entries).

Out of interest, the WHERE clause can be any standard SQL WHERE clause. This example also has the addition of the "old" keyword to the idnum field. The "old.idnum" field kind of means "the version of idnum which existed before this attempted query began". Read the manual for more info. :)