// math reference

SQL SIN function

Returns the sine of an angle expressed in radians: SIN(0) is 0 and SIN(PI()) is about 1.2e-16, not exactly 0.

Kategorie
Math
Returns
float / double
In this category
30 of 82

Syntax

SIN(angle_radians)

Engine-Unterstützung

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

Beispiele

PostgreSQL

SELECT SIN(0) AS zero, SIN(PI()/6) AS half;  -- 0, 0.49999999999999994

PostgreSQL

SELECT SIN(RADIANS(angle_deg)) AS sine
FROM wave_samples;

SQL Server

SELECT SIN(30 * PI() / 180) AS sine_30;  -- 0.49999999999999994

Gut zu wissen

  • The argument is radians. Passing degrees without converting, SIN(30), computes the sine of 30 radians, a completely different angle.
  • SIN(PI()) is about 1.2e-16, not 0: PI() is approximate, so the result of an exact-angle sine is only approximately exact.
  • NULL in, NULL out: SIN of a NULL argument returns NULL on every engine.

Questions about SIN

Does SIN take degrees or radians?

Radians, on all five engines. Convert first: SIN(RADIANS(30)) or SIN(30 * PI() / 180) gives the sine of 30 degrees, 0.49999999999999994 in doubles. Oracle has neither RADIANS nor PI(), so write SIN(30 * ACOS(-1) / 180).

Why is SIN(PI()) not exactly 0?

PI() is a double approximation of pi, so PI() is not exactly the angle whose sine is zero. The result is about 1.2e-16: effectively zero, but not literally.

What does SIN return for NULL input?

NULL. Every trig function propagates NULL, so rows with missing angles simply come back NULL rather than erroring.

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.