SQLite Functions
SQLite Functions Reference
SQLite has many built in functions. This reference contains the string, numeric, date, aggregate, window, JSON and advanced functions.
Click a function to see its syntax, and examples you can try.
SQLite String Functions
| Function | Description |
|---|---|
| CHAR | Returns a text made from Unicode code points |
| CONCAT | Adds two or more texts together |
| CONCAT_WS | Adds two or more texts together, with a separator |
| FORMAT | Formats values into a text, with format codes like %s and %.2f |
| GLOB | Checks if a text matches a pattern, with case sensitivity |
| HEX | Returns the hexadecimal text of a value |
| INSTR | Returns the position of the first occurrence of a text in another text |
| LENGTH | Returns the number of characters in a text |
| LIKE | Checks if a text matches a pattern, without case sensitivity |
| LOWER | Converts a text to lower case |
| LTRIM | Removes characters from the start of a text |
| OCTET_LENGTH | Returns the number of bytes in a text |
| QUOTE | Returns a value written as an SQL literal |
| REPLACE | Replaces all occurrences of a text with another text |
| RTRIM | Removes characters from the end of a text |
| SUBSTR | Returns a part of a text |
| TRIM | Removes characters from the start and the end of a text |
| UNHEX | Turns a hexadecimal text into a blob |
| UNICODE | Returns the Unicode code point of the first character in a text |
| UPPER | Converts a text to upper case |
SQLite Numeric Functions
| Function | Description |
|---|---|
| ABS | Returns the absolute value of a number |
| ACOS | Returns the arc cosine of a number |
| ACOSH | Returns the hyperbolic arc cosine of a number |
| ASIN | Returns the arc sine of a number |
| ASINH | Returns the hyperbolic arc sine of a number |
| ATAN | Returns the arc tangent of a number |
| ATAN2 | Returns the arc tangent of two numbers |
| ATANH | Returns the hyperbolic arc tangent of a number |
| CEIL | Rounds a number up to the nearest integer |
| COS | Returns the cosine of a number |
| COSH | Returns the hyperbolic cosine of a number |
| DEGREES | Converts radians to degrees |
| EXP | Returns e raised to the power of a number |
| FLOOR | Rounds a number down to the nearest integer |
| LN | Returns the natural logarithm of a number |
| LOG | Returns the base 10 logarithm of a number, or the logarithm to another base |
| LOG10 | Returns the base 10 logarithm of a number |
| LOG2 | Returns the base 2 logarithm of a number |
| MOD | Returns the remainder of a division |
| PI | Returns the value of pi |
| POW | Returns a number raised to the power of another number |
| RADIANS | Converts degrees to radians |
| RANDOM | Returns a random integer |
| RANDOMBLOB | Returns a blob with random bytes |
| ROUND | Rounds a number to a given number of decimals |
| SIGN | Returns the sign of a number: -1, 0 or 1 |
| SIN | Returns the sine of a number |
| SINH | Returns the hyperbolic sine of a number |
| SQRT | Returns the square root of a number |
| TAN | Returns the tangent of a number |
| TANH | Returns the hyperbolic tangent of a number |
| TRUNC | Removes the decimals of a number |
SQLite Date Functions
| Function | Description |
|---|---|
| DATE | Returns a date, as YYYY-MM-DD |
| DATETIME | Returns a date and time, as YYYY-MM-DD HH:MM:SS |
| JULIANDAY | Returns the Julian day number of a date |
| STRFTIME | Formats a date, with format codes like %Y and %m |
| TIME | Returns a time, as HH:MM:SS |
| TIMEDIFF | Returns the difference between two dates, as a text |
| UNIXEPOCH | Returns the number of seconds since 1970-01-01 |
SQLite Aggregate Functions
| Function | Description |
|---|---|
| AVG | Returns the average value of an expression |
| COUNT | Returns the number of rows |
| GROUP_CONCAT | Joins the values in a group into one text |
| MAX | Returns the largest value |
| MIN | Returns the smallest value |
| STRING_AGG | Joins the values in a group into one text, with a separator |
| SUM | Returns the sum of the values |
| TOTAL | Returns the sum of the values, as a decimal number |
SQLite Window Functions
| Function | Description |
|---|---|
| CUME_DIST | Returns the cumulative distribution of each row |
| DENSE_RANK | Gives each row a rank, without gaps |
| FIRST_VALUE | Returns the value from the first row in the window frame |
| LAG | Returns a value from a row before the current row |
| LAST_VALUE | Returns the value from the last row in the window frame |
| LEAD | Returns a value from a row after the current row |
| NTH_VALUE | Returns the value from a given row in the window frame |
| NTILE | Splits the rows into a number of groups |
| PERCENT_RANK | Returns the relative rank of each row, from 0 to 1 |
| RANK | Gives each row a rank, with gaps after equal values |
| ROW_NUMBER | Gives each row a number, starting with 1 |
SQLite JSON Functions
| Function | Description |
|---|---|
| JSON | Checks that a text is valid JSON, and returns it minified |
| JSON_ARRAY | Creates a JSON array from values |
| JSON_ARRAY_LENGTH | Returns the number of items in a JSON array |
| JSON_EACH | Returns one row for each item in a JSON array or object |
| JSON_EXTRACT | Returns a value from a JSON text |
| JSON_GROUP_ARRAY | Turns the values in a group into a JSON array |
| JSON_GROUP_OBJECT | Turns the names and values in a group into a JSON object |
| JSON_INSERT | Adds values to a JSON text, but does not change existing values |
| JSON_OBJECT | Creates a JSON object from names and values |
| JSON_PATCH | Merges two JSON objects |
| JSON_QUOTE | Returns an SQL value written as JSON |
| JSON_REMOVE | Removes values from a JSON text |
| JSON_REPLACE | Changes existing values in a JSON text, but does not add new values |
| JSON_SET | Adds or changes values in a JSON text |
| JSON_TREE | Returns one row for each value in a JSON text, also nested values |
| JSON_TYPE | Returns the type of a JSON value |
| JSON_VALID | Checks if a text is valid JSON |
SQLite Advanced Functions
| Function | Description |
|---|---|
| CHANGES | Returns the number of rows changed by the last INSERT, UPDATE or DELETE |
| COALESCE | Returns the first value that is not NULL |
| IFNULL | Returns another value if a value is NULL |
| IIF | Returns one value if a condition is true, and another value if not |
| LAST_INSERT_ROWID | Returns the rowid of the last inserted row |
| NULLIF | Returns NULL if two values are equal |
| SQLITE_VERSION | Returns the version of SQLite |
| TOTAL_CHANGES | Returns the number of rows changed since the connection was opened |
| TYPEOF | Returns the storage class of a value |
| ZEROBLOB | Returns a blob with a number of zero bytes |