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

expected string or Sqlizer, not int error when using CASE WHEN with squirrel #388

Open
liyuan1125 opened this issue Mar 10, 2025 · 0 comments

Comments

@liyuan1125
Copy link

When I try to use the CASE WHEN statement with squirrel to update a column based on multiple conditions, I get the following error:

expected string or Sqlizer, not int

package main

import (
    "fmt"
    sq "github.com/Masterminds/squirrel"
)

func main() {
    amountExpr := sq.Case("order_no").
        When("ORD001", 500).
        When("ORD002", 600)

    sql, _, err := sq.Update("orders").
        Set("amount", amountExpr).
        Where(sq.Eq{"order_no": []string{"ORD001", "ORD002", "ORD003"}}).
        ToSql()

    if err != nil {
        fmt.Println("Error:", err)
        return
    }

    fmt.Println("Generated SQL:", sql)
}

Thank you! 🙏 Would appreciate any insights or guidance on this issue. 😊

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

No branches or pull requests

1 participant