// math reference

SQL COT function

Returns the cotangent of a radian angle: COT(PI()/4) is about 1, and COT(0) is an error or Infinity because tangent is zero there.

Catégorie
Math
Returns
float / double
In this category
33 of 82

Syntaxe

COT(angle_radians)

Prise en charge des moteurs

MoteurSupportNotes
SQL Server Oui COT(x) is built in; COT(0) raises an invalid floating point operation
PostgreSQL Oui cot(x) is built in; cot(0) returns Infinity
MySQL Oui COT(x) is built in; COT(0) raises 'DOUBLE value is out of range'
SQLite Not built in Not in the 3.35+ math set; 1 / TAN(x)
Oracle Not built in No COT; 1 / TAN(x)

Exemples

SQL Server

SELECT COT(PI()/4) AS one;  -- 1 (float-rounding aside)

MySQL

SELECT COT(1) AS cot_one;  -- 0.6420926...

PostgreSQL

SELECT COT(RADIANS(angle_deg)) AS cotangent
FROM slopes;

Oracle

SELECT 1 / NULLIF(TAN(1), 0) AS cot_one FROM dual;  -- .642092616

Bon à savoir

  • COT(0) has no finite value: SQL Server and MySQL raise an error, PostgreSQL returns Infinity.
  • Where it is missing, 1 / TAN(x) is the definition. Guard the zero with NULLIF: 1 / NULLIF(TAN(x), 0). Oracle raises ORA-01476 and SQLite returns NULL without it.
  • Arguments are radians, same as every other trig function.

Questions about COT

Which engines have COT?

SQL Server, PostgreSQL and MySQL ship COT(). SQLite and Oracle do not; compute 1 / NULLIF(TAN(x), 0) there.

What happens at COT(0)?

The cotangent of zero is undefined because TAN(0) is zero. SQL Server and MySQL raise an error; PostgreSQL returns Infinity.

Is COT just 1/TAN?

Mathematically yes, and that identity is exactly the portable replacement. COT(x) = COS(x) / SIN(x) is equivalent.

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.

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