Open Jille opened 8 months ago
Isn't it possible to use CAST
for this?
https://play.sqlc.dev/p/754393cb25dc32e04cb7daf4102621418a45ee448e9d00ba91a6e8fe10afb79d
Maybe? GetAuthorParams.Name
is an interface{}
in your example, where I expected a string.
Yes, it didn’t seem to handle CHAR cast, but some of the other types worked.
:: is simply the postgres specific CAST syntax.
:: is simply the postgres specific CAST syntax.
Yeah, but I had failed to convince MySQL's CAST to do what I wanted. (Maybe because I accidentally tried INTEGER
and STRING
/VARCHAR
rather than trying UNSIGNED
and CHAR
?)
I would prefer having the syntax to be stripped out by sqlc rather than being sent to the database engine by the way, which is why I like the sqlc.arg(foo, int)
approach.
@Jille Our database-agnostic solution for this is https://github.com/sqlc-dev/sqlc/issues/2800. Would that work for you?
What do you want to change?
With postgresql one can write
$1:: integer
and sqlc will make the generated type an integer. MySQL seems to lack such a type cast/assertion.Having that would allow people to work around missing/incorrect type inference.
I propose to use
sqlc.arg(foo, int)
andsqlc.narg(foo, int)
.What database engines need to be changed?
MySQL
What programming language backends need to be changed?
No response