Skip to content

fix: support non-string values in Case When/Then/Else clauses#398

Open
Yanhu007 wants to merge 1 commit intoMasterminds:masterfrom
Yanhu007:fix/case-when-non-string-values
Open

fix: support non-string values in Case When/Then/Else clauses#398
Yanhu007 wants to merge 1 commit intoMasterminds:masterfrom
Yanhu007:fix/case-when-non-string-values

Conversation

@Yanhu007
Copy link
Copy Markdown

Fixes #388

Problem

Passing non-string, non-Sqlizer values (like integers) to Case().When() or .Else() fails with:

expected string or Sqlizer, not int

This makes it impossible to use CASE WHEN with numeric values:

sq.Case("order_no").
    When("'ORD001'", 500).  // ← fails: 500 is int
    Else(0)                       // ← fails: 0 is int

Fix

In part.ToSql(), treat non-string, non-Sqlizer values as parameterized arguments (using ? placeholder) instead of returning an error. This is consistent with how other parts of squirrel handle arbitrary values.

Before: "expected string or Sqlizer, not int" error
After: CASE order_no WHEN 'ORD001' THEN ? ELSE ? END with args [500, 0]

All existing tests pass.

Previously, passing non-string, non-Sqlizer values (e.g., integers)
to Case().When() or .Else() produced an error:
  "expected string or Sqlizer, not int"

This made it impossible to use CASE expressions with numeric values
like:
  sq.Case("order_no").When("ORD001", 500).Else(0)

Now non-string, non-Sqlizer values are treated as parameterized
values (using "?" placeholder), consistent with how other parts of
squirrel handle arbitrary values.

Fixes Masterminds#388
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.

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

1 participant