Convert stored procedures and functions from mysql to plpgsql form