sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

CAST() produces correct go type for postgres but not mysql

Open seanlaff opened this issue 1 year ago • 0 comments

Version

1.25.0

What happened?

CAST and CONVERT don't produce correct go types for mysql

-- name: GetAuthors :many
SELECT id, CAST(name AS CHAR(50)) AS castedName
FROM authors;

produces this for postgres

type GetAuthorsRow struct {
	ID         sql.NullInt32
	Castedname string
}

but this for mysql

type GetAuthorsRow struct {
	ID         sql.NullInt32
	Castedname interface{}
}

As a workaround I can cheat by wrapping cast() with concat().

SELECT id, concat(CAST(name AS CHAR(50))) AS castedName
FROM authors;

Playground URL

https://play.sqlc.dev/p/f564780effa348c312a8a3c85bb9b2cfa093d56538f945ee439aa476847df247

What operating system are you using?

macOS

What database engines are you using?

MySQL

What type of code are you generating?

Go

seanlaff avatar Jan 11 '24 14:01 seanlaff