What's the spec of Column.get(int, Class) supported conversions?

22 views
Skip to first unread message

Lukas Eder

unread,
Apr 9, 2021, 7:36:34 AM4/9/21
to r2dbc
Hi folks, me again :)

In https://r2dbc.io/spec/0.9.0.M1/spec/html/#rows, the specification claims that

> When you specify a target type, the R2DBC driver tries to convert the value to the target type

I'm assuming this conversion is deliberately not specified to allow for implementation specific conversions, right? Nevertheless, from experience with JDBC, one could safely assume that all "reasonable" conversions are supported by all drivers, e.g. any number (e.g. SMALLINT) can be retrieved as any other number type (e.g. java.lang.Long).

This assumption can be verified in some drivers, e.g. the PostgreSQL one.

Before I go and report all issues like these to the respective drivers:


Can you confirm:

- The behaviour is indeed deliberately implementation-specific, and clients will have to implement conversions themselves, or
- The behaviour is implementation-specific to some extent, but some "reasonable" conversions can be expeted to work

In either case, I think some additional remarks in the spec could be useful to make sure expectations meet reality.

Thanks,
Lukas

Mark Paluch

unread,
Apr 9, 2021, 8:10:38 AM4/9/21
to r2dbc
Hi Lukas,

Long time no see. You're right, that the conversion aims at reasonable conversions (conversion of a numeric value if the base type is numeric or extracting date/time parts if the base type is a temporal one). That typically doesn't work is converting a number into a boolean or parsing a character value into a numeric/date type. Also note that streaming types (Blob, Clob) cannot be easily converted into a ByteBuffer or String as those types need to be materialized and conversion could impose blocking behavior.

We can clarify the specification, can you submit either a pull request if you have a specific wording on your mind or a ticket if someone from the spec side should look into it?

Cheers,
Mark

Lukas Eder

unread,
Apr 9, 2021, 9:11:06 AM4/9/21
to r2dbc
Thanks for the feedback, Mark. I've created an issue:

I don't think I can provide specific wording. While I have a decent feeling of what *happens* to work in JDBC, I'm not sure what a specification should look like. A good possibility would be to copy what's specified in the SQL standard ISO/IEC 9075-2:2016(E)  6.13 <cast specification> SR 7) contains a complete matrix of what's convertible to what. If things can be converted in SQL, then they should be convertible in drivers as well give or take a few extra and a few missing vendor-specific conversions...
Reply all
Reply to author
Forward
0 new messages