MB: PLpgSQL functions