Properly quote numerics when casting string columns

Returning the wrong type can cause the wrong index to be used on some
adapters, or even an error. We use `.try` rather than checking for
`nil`, since the tests on 4.1 imply that objects that do not respond to
`type` can be passed as the column for `quote`.

Closes #17345