App Built-in SQL Functions
SQLite database engine provides a number of built-in functions (documentation is provided by official website sqlite.org)
DBCompass for SQLite provides additional sets of functions.
Information
cell_type
(X) β string (returns cell type: integer/float/text/blob/null)
Conversion
celsius2fahrenheit
(real) β real (converts Celsius to Fahrenheit)fahrenheit2celsius
(real) β real (converts Fahrenheit to Celsius)kg2lb
(real) β real (converts Kilogram to Pound)lb2kg
(real) β real (converts Pound to Kilogram)currency_format
(number) β string (formats number to text using device currency settings)
String
- π
unicode_lower
(string) β string (returns the input string with all unicode characters converted to lower case) - π
unicode_upper
(string) β string (returns the input string with all unicode characters converted to upper case) - π
unicode_reverse
(string) β string (returns the input string with all unicode characters reversed) - π
unaccent
(string) β string (e.g. βHΓ΄w ΓrΓ« YΓ²Ε―?β β βHow Are You?β) capitalized
(string) β string (e.g. βhow are you?β β βHow Are You?β)stringLength
(string) β integer (returns the number of unicode characters, not the bytes)stringCharAt
(string,int) β string (returns the unicode character at the position)splitPart
(string,string,int) β string (splits string by separator and returns index part)
Other (contrib) String functions are described in the section below.
Date
-
date2unix
(pattern,datestring) β reale.g. pattern:
'yyyy-MM-dd HH:mm:ss'
(case sensitive) or'iso8601'
-
date2date
(pattern-in,datestring,pattern-out) β stringe.g. pattern:
'yyyy-MM-dd HH:mm:ss'
(case sensitive) or'iso8601'
-
date2part
(pattern-in,datestring,part-out) β stringe.g. part-out possibilities:
'year'
,'month'
,'day'
,'hour'
,'minute'
,'second'
,'weekday'
,'weekofyear'
-
isoDateTime
() β string (returns current date time in ISO-8601 format) localisoDateTime
() β string (returns current date time in ISO-8601 format with local timezone)unix_time
() β real (returns current Unix epoc time)
Pattern | Description | Example |
---|---|---|
yy | 2-digit year | 25 |
yyyy | 4-digit year | 2025 |
M | 1 or 2 digit month | 1 |
MM | 2-digit month | 01 |
d | 1 or 2 digit day of the month | 2 |
dd | 2-digit day of the month | 02 |
h | 1 or 2 digit hour (12-hour format) | 1 |
hh | 2-digit hour (12-hour format) | 01 |
H | 1 or 2 digit hour (24-hour format) | 15 |
HH | 2-digit hour (24-hour format) | 15 |
m | 1 or 2 digit minute | 2 |
mm | 2-digit minute | 02 |
s | 1 or 2 digit second | 2 |
ss | 2-digit second | 02 |
SSS | The milliseconds | 123 |
a | AM/PM for 12-hour format | PM |
Z | RFC 822 GMT format | -0600 |
ZZZZZ | ISO 8601 time zone format | -06:00 |
Pattern string is case-sensitive.
Encoding
base64
(X) β string (encodes blob field to Base64 string)decode_base64
(string) β blob (decodes Base64 string to blob)unhex
(string) β blob (decodes HEX string to blob)
Hashing
sha1
(X) β hexstring (returns SHA 1 checksum)sha256
(X) β hexstring (returns SHA 256 checksum)sha384
(X) β hexstring (returns SHA 384 checksum)sha512
(X) β hexstring (returns SHA 512 checksum)sha3_224
(X) β hexstring (returns SHA3-224 checksum)sha3_256
(X) β hexstring (returns SHA3-256 checksum)sha3_384
(X) β hexstring (returns SHA3-384 checksum)sha3_512
(X) β hexstring (returns SHA3-512 checksum)
Encryption
aes_cbc_encrypt
(string, key:blob, iv:blob) β blob (encrypts text string with AES CBC, iv can be null)aes_cbc_decrypt
(blob, key:blob, iv:blob) β string (decrypts encrypted blob with AES CBC, iv can be null)aes_gcm_encrypt
(string, key:blob) β blob (encrypts text string with AES GCM)aes_gcm_decrypt
(blob, key:blob) β string (decrypts encrypted blob with AES GCM)chachapoly_encrypt
(string, key:blob) β blob (encrypts text string with ChaCha20-Poly1305)chachapoly_decrypt
(blob, key:blob) β string (decrypts encrypted blob with ChaCha20-Poly1305)chachapoly_decrypt
(blob, key:blob) β string (decrypts encrypted blob with ChaCha20-Poly1305)
Generator
random_text
(N) β string (generates a random text of length n)random_number
(from, to) β Number (generates a random number in the specified range)secure_random
() β Number (generates a secure random number)uuid
() oruuid_v4
() β string (generates UUID v4 string value)uuid_v1
() β string (generates UUID v1 string value)uuid_v7
() β string (generates UUID v7 string value)cuid
() β string (generates CUID v1 string value)cuid2
() β string (generates CUID v2 string value)
Regex
regexp
(string, regex) β int 0/1 (this can be used also as operator: βS REGEXP Rβ)regex_replace
(regex, string, replacement) β string
Image
create_qr_code_image
(string) β blob (generates a PNG QR code image from input text)
Geohash
geohash_encode
(real,real,integer) β string (converts latitude/longitude/precision to a geohash text)geohash_decode_latitude
(string) β real (converts geohast to latitude)geohash_decode_longitude
(string) β real (converts geohast to longitude)
XML
- π
filter_xml
(string,string) β string (returns XML content given an XML as first parameter and an XPath as second)
Web
- π
encode_url
(string) β string (returns a URL-encoded string) - π
get_url
(string) β string (retrieves the URL-encoded string and return the content)
Contrib Functions
Math
-
acos
(X) β Returns the arccosine of X. The result is in radians -
acosh
(X) β Returns the hyperbolic arccosine of X -
asin
(X) β Returns the arcsine of X. The result is in radians -
asinh
(X) β Returns the hyperbolic arcsine of X -
atan
(X) β Returns the arctangent of X. The result is in radians -
atan2
(Y,X) β Returns the arctangent of Y/X. The result is in radians. The result is placed into correct quadrant depending on the signs of X and Y -
atanh
(X) β Returns the hyperbolic arctangent of X -
π
cbrt
(X) β Returns cube root of X -
ceil
(X),ceiling
(X) β Returns the first representable integer value greater than or equal to X. For positive values of X, this routine rounds away from zero. For negative values of X, this routine rounds toward zero -
cos
(X) β Returns the cosine of X. X is in radians -
cosh
(X) β Returns the hyperbolic cosine of X -
degrees
(X) β Converts value X from radians into degrees -
exp
(X) β Computes e (Euler's number, approximately 2.71828182845905) raised to the power X -
floor
(X) β Returns the first representable integer value less than or equal to X. For positive numbers, this function rounds toward zero. For negative numbers, this function rounds away from zero -
π
gamma
(X) β Returns the gamma function -
log
(X),log10
(X),log
(B,X) β Returns the base-10 logarithm for X. Or, for the two-argument version, return the base-B logarithm of X
Compatibility note
SQLite works like PostgreSQL in that the log() function computes a base-10 logarithm. Most other SQL database engines compute a natural logarithm for log(). In the two-argument version of log(B,X), the first argument is the base and the second argument is the operand. This is the same as in PostgreSQL and MySQL, but is reversed from SQL Server which uses the second argument as the base and the first argument as the operand-
log2
(X) β Returns the logarithm base-2 for the number X -
mod
(X,Y) β Returns the remainder after dividing X by Y. This is similar to the '%' operator, except that it works for non-integer arguments -
pi
() β Returns an approximation for Ο -
pow
(X,Y),power
(X,Y) β Computes X raised to the power Y -
radians
(X) β Converts X from degrees into radians -
sin
(X) β Returns the sine of X. X is in radians -
sinh
(X) β Returns the hyperbolic sine of X -
sqrt
(X) β Returns the square root of X. NULL is returned if X is negative -
tan
(X) β Returns the tangent of X. X is in radians -
tanh
(X) β Returns the hyperbolic tangent of X -
trunc
(X) β Returns the representable integer in between X and 0 (inclusive) that is furthest away from zero. Or, in other words, return the integer part of X, rounding toward zero. The trunc() function is similar to ceiling(X) and floor(X) except that it always rounds toward zero whereas ceiling(X) and floor(X) round up and down, respectively.
Aggregate
stdev
, variance
, mode
, median
, lower_quartile
, upper_quartile
String
-
replicate
β Given a string (s) in the first argument and an integer (n) in the second returns the string that contains s concatenated n times -
charindex
β Given 2 input strings (s1,s2) and an integer (n) searches from the nth character for the string s1. Returns the position where the match occurred. Characters are counted from 1. 0 is returned when no match occurs. -
leftstr
β Given a string (s) and an integer (n) returns the n leftmost (UTF-8) characters if the string has a length<=n or is NULL this function is NOP -
rightstr
β Given a string (s) and an integer (n) returns the n rightmost (UTF-8) characters if the string has a length<=n or is NULL this function is NOP -
reverse
β Given a string returns the same string but with the characters in reverse order -
padl
β Given an input string (s) and an integer (n) adds spaces at the beginning of s until it has a length of n characters. When s has a length<=n itβs a NOP. padl(NULL) = NULL -
padr
β Given an input string (s) and an integer (n) adds spaces at the end of s until it has a length of n characters. When s has a length<=n itβs a NOP. padl(NULL) = NULL -
padc
β Given an input string (s) and an integer (n) adds spaces at the end of s and adds spaces at the beginning of s until it has a length of n characters. Tries to add has many characters at the left as at the right. When s has a length<=n itβs a NOP. padl(NULL) = NULL -
strfilter
β Given 2 string (s1,s2) returns the string s1 with the characters NOT in s2 removed assumes strings are UTF-8 encoded
IEEE 754 π
The ieee754 extension converts a floating point number between its binary64 representation and the MΓ2E format. In other words in the expression:
F = M Γ 2E
The ieee754 extension converts between F and (M,E) and back again.
-
ieee754
(F) β Takes a single floating-point argument as its input and returns a string like 'ieee754(M,E)' -
ieee754
(M,E) β Takes the mantissa (M) and exponent (E) values and converts them into the corresponding float value -
ieee754_mantissa
(F) β Returns the mantissa of the specified float number -
ieee754_exponent
(F) β Returns the exponent of the specified float number -
ieee754_from_blob
(B) β Converts a blob into binary64 number -
ieee754_to_blob
(F) β Converts a binary64 number into blob -
ieee754_inc
(r,N) β Moves the floating point value r by N quantums and return the new values
Decimal π
The decimal extension provides arbitrary-precision decimal arithmetic on numbers stored as text strings. Because the numbers are stored to arbitrary precision and as text, no approximations are needed. Computations can be done exactly.
-
decimal
(X) β Returns a complete decimal, without the e+NNN at the end -
decimal_exp
(X) β Returns the result in exponential notation -
decimal_cmp
(X,Y) β Returns negative, zero, or positive if X is less then, equal to, or greater than Y -
decimal_add
(X,Y) β Returns the sum of X and Y -
decimal_sub
(X,Y) β Returns the difference of X and Y -
decimal_mul
(X,Y) β Returns the product of X and Y -
decimal_pow2
(N) β Returns the N-th power of 2. N must be an integer