// 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.

Categoria
Math
Returns
float / double
In this category
32 of 82

Sintaxe

TAN(angle_radians)

Suporte a mecanismos

MotorSupportNotas
SQL Server Sim Supported under this name.
PostgreSQL Sim Supported under this name.
MySQL Sim Supported under this name.
SQLite Sim Requires SQLite 3.35+ with the math functions built in
Oracle Sim Supported under this name.

Exemplos

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

Bom saber

  • 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.