Calculated field
ATAN2([score], [other])
Sample data
| id | amount | units | score | other |
|---|---|---|---|---|
| 1 | -2.5 | 2 | -0.8 | 3 |
| 2 | 0 | 0 | 0 | 4 |
| 3 | 1.5 | 3 | 0.25 | 2 |
| 4 | 4 | 4 | 0.5 | 8 |
| 5 | 9 | 5 | 0.8 | 11 |
| 6 | 16 | 6 | 1 | 14 |
| 7 | null | 7 | null | 9 |
| 8 | 4 | 8 | -0.5 | null |
The same calculation as SQL
SELECT atan2(score,other) AS result FROM input ORDER BY id
Runs the example above.
SELECT atan2(score,other) AS result FROM input ORDER BY id
Written for this dialect; not run here.
SELECT atan2(score,other) AS result FROM input ORDER BY id
Written for this dialect; not run here.
Result
| id | amount | units | score | result |
|---|---|---|---|---|
| 1 | -2.5 | 2 | -0.8 | -0.260602 |
| 2 | 0 | 0 | 0 | 0 |
| 3 | 1.5 | 3 | 0.25 | 0.124355 |
| 4 | 4 | 4 | 0.5 | 0.0624188 |
| 5 | 9 | 5 | 0.8 | 0.0725995 |
| 6 | 16 | 6 | 1 | 0.0713075 |
| 7 | null | 7 | null | null |
| 8 | 4 | 8 | -0.5 | null |
Same rows from the calculation and from the SQL in DuckDB.
Where a naive translation goes wrong
- Replacing null results with zero changes missing-value semantics.
Naive SQL
SELECT coalesce((atan2(score,other)),0) AS result FROM input ORDER BY id
id amount units score result 1 -2.5 2 -0.8 -0.260602 2 0 0 0 0 3 1.5 3 0.25 0.124355 4 4 4 0.5 0.0624188 5 9 5 0.8 0.0725995 6 16 6 1 0.0713075 7 null 7 null 0 8 4 8 -0.5 0 Matches the calculation
SELECT atan2(score,other) AS result FROM input ORDER BY id
id amount units score result 1 -2.5 2 -0.8 -0.260602 2 0 0 0 0 3 1.5 3 0.25 0.124355 4 4 4 0.5 0.0624188 5 9 5 0.8 0.0725995 6 16 6 1 0.0713075 7 null 7 null null 8 4 8 -0.5 null
Signature
ATAN2(number, number)