Calculated field
MID([label], 2, 4)
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 substr(label,2,4) AS result FROM input
Runs the example above.
SELECT substr(label,2,4) AS result FROM input
Written for this dialect; not run here.
SELECT substr(label,2,4) AS result FROM input
Written for this dialect; not run here.
Result
| result |
|---|
| ced |
| RCHI |
| aple |
| illo |
| irch |
| ine/ |
| sh |
| null |
Same rows from the calculation and from the SQL in DuckDB.
Where a naive translation goes wrong
- Replacing MID with substr(label,3,4) changes the shown values or null handling.
Naive SQL
SELECT substr(label,3,4) AS result FROM input
result ceda CHID ple- llow rch- ne/s h null Matches the calculation
SELECT substr(label,2,4) AS result FROM input
result ced RCHI aple illo irch ine/ sh null
Signature
MID(string, start, [length])