In PostgreSQL, sin()
is a mathematical function that returns the trigonometric sine of the specified angle, as measured in radians.
You specify the angle by providing an argument to the function when calling it.
In trigonometry, sine is the function that is equal to the ratio of the side opposite a given angle (in a right-angled triangle) to the hypotenuse.
Syntax
The syntax goes like this:
sin(x)
Where x
is a double precision value that represents the angle (in radians) for which you want the sine returned.
Example
Here’s an example to demonstrate how it works.
SELECT sin(2);
Result:
0.9092974268256817
Fractions
The angle can contain a fractional component.
SELECT sin(1.2345);
Result:
0.9439833239445111
Negative Angles
The angle can be negative.
SELECT sin(-2);
Result:
-0.9092974268256817
Expressions
The argument can include expressions.
SELECT sin(1.5 * 2);
Result:
0.1411200080598672
Passing Other Functions
Here’s an example that includes another function (in this case pi()
) in the expression.
SELECT sin(pi()/2);
Result:
1
Specify the Angle in Degrees
As mentioned, the angle you provide to sin()
is specified in radians. To specify it in degrees, use the sind()
function.
The sind()
function works exactly the same as sin()
, except that its argument is specified in degrees instead of radians.