Implement cast function parser for MySQL #2020
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is this
As the title said, this PR wants to add support for
CAST
function in MySQL.This PR is based from PR by @ryanpbrewster here (which unfortunately he didn't send here, and only exist in his repository).
Why is this PR created
Currently
sqlc
unable to infer the correct type from SQL function likeMAX
,MIN
,SUM
, etc. For those function, sqlc will return its value asinterface{}
. This behavior can be seen in this playground.As workaround, it advised to use
CAST
function to explicitly tell what is the type for that column, as mentioned in #1574.Unfortunately, currently sqlc only support
CAST
function in PostgreSQL and not in MySQL. Thanks to this, right now MySQL users have to parse theinterface{}
manually, which is not really desirable.What does this PR do?
convertFuncCast
function for MySQL.convertFuncCast
.I haven't write any test because I'm not sure how and where to put it. However, as far as I know the code that handle
ast.TypeCast
for PostgreSQL also don't have any test, so I guess it's fine 🤷♂️Related issues