Skip to content

Conversation

@kyleconroy
Copy link
Collaborator

@kyleconroy kyleconroy commented Oct 13, 2023

MySQL and PostgreSQL now have the same behavior, generating a nullable string parameter. That behavior isn't right, as we'd expect the parameter to be a boolean. This can be fixed by using a type case or the new annotations in #2800.

Fixes #2847

SET value = CASE ? WHEN true THEN 'Hello' WHEN false THEN 'Goodbye' ELSE value END
`

func (q *Queries) Update(ctx context.Context, value sql.NullString) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this generated func parameter be a boolean to match the cases and not a string which matches the output?

list.Items = append(list.Items, c.convertWhenClause(n))
}
return &ast.CaseExpr{
Arg: c.convert(n.Value),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After looking at the test output, I think n.Value isn't correct here.

@kyleconroy kyleconroy merged commit 9313007 into main Oct 13, 2023
@kyleconroy kyleconroy deleted the kyle/mysql-case-value branch October 13, 2023 18:37
alfonsodev pushed a commit to ExponentiaTeam/sqlc that referenced this pull request Oct 13, 2025
MySQL and PostgreSQL now have the same behavior, generating a nullable string parameter. That behavior isn't right, as we'd expect the parameter to be a boolean. This can be fixed by using a type case or the new annotations in sqlc-dev#2800.

Fixes sqlc-dev#2847
Sign up for free to 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.

No parameter gets generated for CASE ? WHEN...

3 participants