CONTRIB-3528 Fixed CAST bugs with PostgreSQL

Signed-off-by: Joseph Rézeau <moodle@rezeau.org>