fixed postgres errors

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