Calculated field
[label] IN ('ash', 'pine/south')
Sample data
| label | quantity | amount | flag |
|---|---|---|---|
| cedar cedar | 65 | 12.8 | True |
| ORCHID-west | 66 | -7.6 | False |
| maple-east | 67 | 0 | null |
| willow north | 68 | 25.3 | True |
| birch-birch | 69 | 4.9 | False |
| pine/south | 70 | -1.2 | null |
| ash | 71 | 9 | True |
| null | null | null | null |
The same calculation as SQL
SELECT coalesce(label IN ('ash','pine/south'),false) AS result FROM inputRuns the example above.
SELECT coalesce(label IN ('ash','pine/south'),false) AS result FROM inputWritten for this dialect; not run here.
SELECT coalesce(label IN ('ash','pine/south'),false) AS result FROM inputWritten for this dialect; not run here.
Result
| result |
|---|
| False |
| False |
| False |
| False |
| False |
| True |
| True |
| False |
Same rows from the calculation and from the SQL in DuckDB.
Where a naive translation goes wrong
- Replacing IN with label IN ('ash','pine/south') changes the shown values or null handling.
Naive SQL
SELECT label IN ('ash','pine/south') AS result FROM inputresult False False False False False True True null Matches the calculation
SELECT coalesce(label IN ('ash','pine/south'),false) AS result FROM inputresult False False False False False True True False
Signature
IN(expression, member, ...)