SQL

Functions

You can use various types of functions in your SQL queries to perform operations on your data.

Math and Trigonometry

Node supports the math functions shown in the following table of math functions plus trigonometry functions listed at the end of this section. Most math functions and all trig functions take these input types:

  • INTEGER
  • BIGINT
  • FLOAT
  • DOUBLE
  • SMALLINT
  • DECIMAL

Table of Math Functions

FunctionReturn TypeDescription
ABS(x)Same as inputReturns the absolute value of the input argument x.
CBRT(x)FLOAT8Returns the cubic root of x.
CEIL(x)Same as inputReturns the smallest integer not less than x.
CEILING(x)Same as inputSame as CEIL.
DEGREES(x)FLOAT8Converts x radians to degrees.
E()FLOAT8Returns 2.718281828459045.
EXP(x)FLOAT8Returns e (Euler's number) to the power of x.
FLOOR(x)Same as inputReturns the largest integer not greater than x.
LOG(x)FLOAT8Returns the natural log (base e) of x.
LOG(x, y)FLOAT8Returns log base x to the y power.
LOG10(x)FLOAT8Returns the common log of x.
LSHIFT(x, y)Same as inputShifts the binary x by y times to the left.
MOD(x, y)FLOAT8Returns the remainder of x divided by y.
NEGATIVE(x)Same as inputReturns x as a negative number.
PIFLOAT8Returns pi.
POW(x, y)FLOAT8Returns the value of x to the y power.
RADIANS(x)FLOAT8Converts x degrees to radians.
RANDFLOAT8Returns a random number from 0-1.
ROUND(x)Same as inputRounds to the nearest integer.
ROUND(x, y)DECIMALRounds x to y decimal places.
RSHIFT(x, y)Same as inputShifts the binary x by y times to the right.
SIGN(x)INTReturns the sign of x.
SQRT(x)Same as inputReturns the square root of x.
TRUNC(x, y)DOUBLETruncates x to y decimal places. Specifying y is optional. Default is 0.

Trigonometry Functions

Node supports the following trigonometryfunctions, which return a FLOAT8 result.

  • SIN(x)
    Sine of angle x in radians
  • COS(x)
    Cosine of angle x in radians
  • TAN(x)
    Tangent of angle x in radians
  • ASIN(x)
    Inverse sine of angle x in radians
  • ACOS(x)
    Inverse cosine of angle x in radians
  • ATAN(x)
    Inverse tangent of angle x in radians
  • SINH()
    Hyperbolic sine of hyperbolic angle x in radians
  • COSH()
    Hyperbolic cosine of hyperbolic angle x in radians
  • TANH()
    Hyperbolic tangent of hyperbolic angle x in radians

Date/Time Functions and Arithmetic

In addition to the TO_DATE, TO_TIME, and TO_TIMESTAMP functions, Node supports a number of other date/time functions and arithmetic operators for use with dates, times, and intervals. Node supports time functions based on the Gregorian calendar and in the range 1971 to 2037.

FunctionReturn Type
AGE(TIMESTAMP)INTERVALDAY or INTERVALYEAR
EXTRACT(field from time_expression)DOUBLE
CURRENT_DATEDATE
CURRENT_TIMETIME
CURRENT_TIMESTAMPTIMESTAMP
DATE_ADDDATE, TIMESTAMP
DATE_DIFFDATE, TIMESTAMP
DATE_PARTDOUBLE
DATE_SUBDATE, TIMESTAMP
LOCALTIMETIME
LOCALTIMESTAMPTIMESTAMP
NOWTIMESTAMP
TIMEOFDAYVARCHAR
UNIX_TIMESTAMPBIGINT
NEARESTDATETIMESTAMP
TIMESTAMPADDInferred based on unit of time
TIMESTAMPDIFFInferred based on unit of time
  • NEARESTDATE

This function rounds the TIMESTAMP object passed to it to the nearest unit also passed to the function. For example SELECT * NEARESTDATE(COLUMN,'MONTH') will return all of the TIMESTAMPs in a given column rounded to the nearest month.

String Manipulation

You can use the following string functions in SQL queries:

FunctionReturn Type
BYTE_SUBSTRBINARY or VARCHAR
CHAR_LENGTHINTEGER
CONVARCHAR
CONTAINSVARCHAR
ILIKEBOOLEAN
INITCAPVARCHAR
LENGTHINTEGER
LIKEBOOLEAN
LOWERVARCHAR
LPADVARCHAR
LTRIMVARCHAR
MASKVARCHAR
POSITIONINTEGER
REGEXP_MATCHESBOOLEAN
REGEXP_REPLACEVARCHAR
REPEATVARCHAR
REPLACEVARCHAR
REVERSEVARCHAR
RPADVARCHAR
RTRIMVARCHAR
SPLITINTEGER
SPLIT_PARTVARCHAR
STRPOSINTEGER
SUBSTRVARCHAR
TOASCIIVARCHAR
TRIMVARCHAR
UPPERVARCHAR