Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement cast function parser for MySQL #2020

Closed
wants to merge 1 commit into from
Closed

Implement cast function parser for MySQL #2020

wants to merge 1 commit into from

Conversation

RadhiFadlillah
Copy link
Contributor

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 like MAX, MIN, SUM, etc. For those function, sqlc will return its value as interface{}. 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 the interface{} manually, which is not really desirable.

What does this PR do?

  • Implement convertFuncCast function for MySQL.
  • Add better nil pointer check in some functions that related to 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

@RadhiFadlillah RadhiFadlillah closed this by deleting the head repository Apr 29, 2023
@abh
Copy link

abh commented Jul 18, 2023

Why was this closed?

@RadhiFadlillah
Copy link
Contributor Author

Oh, my bad. It seems I've deleted my fork for this PR by accident when I was deleting several of my unused repositories.

TIL: The PR will be closed automatically if the fork is erased.

@RadhiFadlillah
Copy link
Contributor Author

I'm unable to recover the deleted repository so I decided to just recreate the PR. Sorry for the trouble 😓

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants