PostgreSQL - use TO_CHAR instead of CAST