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

Error: has incompatible types: sql.NullString, interface{} #3656

Open
omid9h opened this issue Oct 15, 2024 · 1 comment
Open

Error: has incompatible types: sql.NullString, interface{} #3656

omid9h opened this issue Oct 15, 2024 · 1 comment

Comments

@omid9h
Copy link

omid9h commented Oct 15, 2024

I have a MySQL query with multiple named parameters. everything is fine but for bellow chunk:

AND (
    sqlc.narg(phone_filter) IS NULL
    OR (
        (
            length (sqlc.narg(phone_filter)) != 11
            OR aes_decrypt (from_base64 (u.phone), sqlc.arg(aes_key)) = sqlc.narg(phone_filter)
        )
        AND (
            length (sqlc.narg(phone_filter)) = 11
            OR aes_decrypt (from_base64 (u.phone), sqlc.arg(aes_key)) LIKE '%' || sqlc.narg(phone_filter) || '%'
        )
    )
)

and for the last line OR aes_decrypt (from_base64 (u.phone), sqlc.arg(aes_key)) LIKE '%' || sqlc.narg(phone_filter) || '%'

I get this error:

# package demorepo error generating code: named param PhoneFilter has incompatible types: sql.NullString, interface{}

any idea how to fix this? thanks

@dosubot dosubot bot added the 📚 mysql label Oct 15, 2024
@omid9h
Copy link
Author

omid9h commented Oct 15, 2024

Something that I've found is that sqlc assumes the parameter here at LIKE '%' || sqlc.narg(phone_filter) || '%' to be interface{} and apparently it conflicts with sql.NullString which is assumed in above lines.

I was able to solve the error simply by using another param like sqlc.narg(phone_filter2) but my question is how can define the type explicitly. I've tried ::<type> but I get syntax error.

@omid9h omid9h closed this as completed Oct 15, 2024
@omid9h omid9h reopened this Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant