SQL ATANH function
Returns the inverse hyperbolic tangent for inputs in (-1, 1): ATANH(0) is 0 and ATANH(0.5) is about 0.5493.
- 类别
- Math
- Returns
float / double- In this category
- 46 of 82
语法
ATANH(number)
引擎支持
| 引擎 | Support | 备注 |
|---|---|---|
| SQL Server | Not built in | No hyperbolic functions; use 0.5 * LOG((1 + x) / (1 - x)) |
| PostgreSQL | 是 | Built in since PostgreSQL 12 |
| MySQL | Not built in | No inverse hyperbolic functions; use the LN identity |
| SQLite | 是 | Built in on 3.35+ |
| Oracle | Not built in | No ATANH; use 0.5 * LN((1 + x) / (1 - x)) |
示例
PostgreSQL
SELECT ATANH(0) AS zero, ATANH(1) AS edge; -- 0, Infinity
SQL Server
SELECT 0.5 * LOG((1 + 0.5) / (1 - 0.5)) AS atanh_half; -- about 0.5493
PostgreSQL
SELECT ATANH(LEAST(0.999999, GREATEST(-0.999999, r))) AS fisher_z FROM correlations;
值得了解
- At the edges the answer is infinite: ATANH(1) returns Infinity on PostgreSQL and Inf on SQLite, not an error. Past the edge, ATANH(1.5) is an error on PostgreSQL and NULL on SQLite.
- Clamp correlations before calling: r computed in floats can be 1.0000000000000002, which errors on PostgreSQL, and a perfect r = 1 gives an infinite z that breaks later averages.
- The artanh formula 0.5 * LN((1+x)/(1-x)) is the portable path; SQL Server spells LN as LOG.
Questions about ATANH
What does ATANH return for exactly 1?
TANH reaches 1 only at infinity, so the inverse at 1 is infinite. PostgreSQL returns Infinity and SQLite Inf, so the query does not fail but the value poisons any later SUM or AVG. Values beyond 1 error on PostgreSQL and give NULL on SQLite.
What is the portable ATANH formula?
0.5 * LN((1 + x) / (1 - x)) for |x| < 1. On SQL Server, write LOG for LN.
How is ATANH used in statistics?
It is the Fisher z-transformation of a correlation coefficient, which is exactly why inputs of exactly 1 show up and need clamping.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
Cheat sheets for the engines that have it: PostgreSQL, SQLite.
Functions your engine actually has
SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.