Fixed postgres errors

I've made an attempt to fix the various error thrown by Elis in Postgres. For more details see http://www.thetravelingprogrammer.com/postgres-support-moodle-elis-2-6/