Calculated field
STR([quantity])
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 quantity::varchar AS result FROM input
Runs the example above.
SELECT CAST(quantity AS VARCHAR) AS result FROM input
Written for this dialect; not run here.
SELECT CAST(quantity AS STRING) AS result FROM input
Written for this dialect; not run here.
Result
| result |
|---|
| 65 |
| 66 |
| 67 |
| 68 |
| 69 |
| 70 |
| 71 |
| null |
Same rows from the calculation and from the SQL in DuckDB.
Where a naive translation goes wrong
- Replacing STR with quantity::varchar || ' units' changes the shown values or null handling.
Naive SQL
SELECT quantity::varchar || ' units' AS result FROM input
result 65 units 66 units 67 units 68 units 69 units 70 units 71 units null Matches the calculation
SELECT quantity::varchar AS result FROM input
result 65 66 67 68 69 70 71 null
Signature
STR(expression)