http://people.planetpostgresql.org/greg/index.php?/categories/19-PlPgsql some interesting notes on PL/PGSQL programing