SQUARE in JS

Unfortunately, JavaScript does not provide a method to calculate the square of a number directly. This can be solved using the pow function.

Sample Source Pattern

Implementation of stored procedure

CREATE OR REPLACE FUNCTION square(exp float)
  RETURNS float
  LANGUAGE JAVASCRIPT
AS
$$
  return Math.pow(exp, 2);
$$
;
SELECT SQUARE(16);

Arguments

exp: Numeric expression to be raised.

Return Type

Float.

Last updated