// math reference

SQL TAN function

Returns the tangent of an angle expressed in radians: TAN(0) is 0 and the result grows without bound near PI()/2.

Категория
Math
Returns
float / double
In this category
32 of 82

Синтаксис

TAN(angle_radians)

Поддержка движка

ДвижокSupportЗаметки
SQL Server Да Supported under this name.
PostgreSQL Да Supported under this name.
MySQL Да Supported under this name.
SQLite Да Requires SQLite 3.35+ with the math functions built in
Oracle Да Supported under this name.

Примеры

PostgreSQL

SELECT TAN(0) AS zero, TAN(PI()/4) AS one;  -- 0, 0.9999999999999999

PostgreSQL

SELECT TAN(RADIANS(slope_deg)) AS rise_over_run
FROM grades;

SQL Server

SELECT TAN(PI()/2) AS huge;  -- about 1.63e16, not infinity

Полезно знать

  • There is no vertical asymptote error: TAN(PI()/2) returns about 1.6e16, a huge finite value, because PI()/2 in floats is not exactly a right angle.
  • The argument is radians; TAN(45) is the tangent of 45 radians, not 45 degrees.
  • Results can be anything (there is no [-1, 1] bound like SIN and COS), so plausibility checks tuned for those will not transfer.

Questions about TAN

What does TAN(PI()/2) return?

A huge finite number, about 1.6e16, not an error and not infinity: PI()/2 as a double is not exactly a right angle, so the tangent is defined but enormous.

Why does TAN give a wild value for my angle?

Either the angle is in degrees and you passed radians, or it sits near PI()/2 where tangent is mathematically unbounded. Convert with RADIANS() and check proximity to right angles.

Does TAN ever error?

Only on invalid input types. The tangent itself is defined everywhere except exact right angles, which floats never hit exactly, so engines return large finite numbers.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite, Oracle.

// fewer lookups

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.