replaced type_cast with type_cast_for_database