Skip to content

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 @ryanpbrewsterhere (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

@RadhiFadlillahRadhiFadlillah 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
ContributorAuthor

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
ContributorAuthor

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

Sign up for freeto 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

@RadhiFadlillah@abh