Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Type-hinting for MySQL? #686

Answered by kyleconroy
alecbz asked this question in Issue Triage
Discussion options

Is there a way to get the "type hinting" in https://github.com/kyleconroy/sqlc/blob/master/docs/named_parameters.md (e.g., sqlc.arg(set_name)::bool) to work for MySQL?

I'm trying to get types for a query like:

SELECT * FROM things
WHERE x = sqlc.arg(x)
 AND y = sqlc.arg(y)
 AND ABS(DATEDIFF(created_at, sqlc.arg(created_at))) < 15;

but CreatedAt in the result struct is an interface{} (and sqlc outputs " unknown MySQL type: any")

Trying to do a MySQL-style CAST(sqlc.arg(created_at) AS DATETIME) results in sqlc getting confused and just omitting the CreatedAt arg altogether.

Is this supposed to work right now, or is it a known issue that more work needs to be done to support this?

You must be logged in to vote

Is this supposed to work right now

Nope!

or is it a known issue that more work needs to be done to support this?

Most certainly a known issue. The sqlc.arg(set_name)::bool syntax is PostgreSQL syntactic sugar for CAST ... AS. I've opened #687 to track implementation.

I'd also like to point out #655, which would also fix your issue. Since the DATEDIFF function takes two arguments of known types, sqlc will pick the correct type automatically. The issue is that I haven't generated the functions definitions yet. Soon!

Replies: 1 comment

Comment options

Is this supposed to work right now

Nope!

or is it a known issue that more work needs to be done to support this?

Most certainly a known issue. The sqlc.arg(set_name)::bool syntax is PostgreSQL syntactic sugar for CAST ... AS. I've opened #687 to track implementation.

I'd also like to point out #655, which would also fix your issue. Since the DATEDIFF function takes two arguments of known types, sqlc will pick the correct type automatically. The issue is that I haven't generated the functions definitions yet. Soon!

You must be logged in to vote
0 replies
Answer selected by alecbz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /