Correct UPDATE statements to work with PostgreSQL.

Please merge this commit as it enables the Moodle 1.9 -> 2.2 -> 2.4 upgrade.