When filtering, cast columns only for PostgreSQL.

Please check if it's OK with other database than PostgreSQL.