In PostgreSQL, the LEAST()
function returns the smallest value from a list of any number of expressions.
The LEAST()
function is not included in the SQL standard, but it’s a popular extension that many major RDBMSs support.
In PostgreSQL, the LEAST()
function returns the smallest value from a list of any number of expressions.
The LEAST()
function is not included in the SQL standard, but it’s a popular extension that many major RDBMSs support.
In MariaDB, the NULLIF()
function returns NULL
if both of its arguments are equivalent. Otherwise it returns the first argument.
MySQL has an IFNULL()
function that allows us to easily replace NULL values with another value.
Most major DBMSs provide us with a function for replacing null values with another value.
But the name of the function tends to differ across DBMSs. For example, SQL Server has an ISNULL()
function, while others (such as MySQL, MariaDB, and SQLite) have an IFNULL()
function for doing the same thing.
However, to confuse matters, MySQL and MariaDB each have an ISNULL()
function that works differently to SQL Server’s function of the same name (MySQL and MariaDB’s implementation only accept a single argument, and return 1
if its null
and 0
if it’s not).
In MySQL, the ISNULL()
function enables us to check whether a value is null
or not. If it’s null
, then 1
is returned, otherwise 0
is returned.
In MariaDB, the IFNULL()
function allows us to replace NULL values with another value.
From MariaDB 10.3, NVL()
can be used as an alias for the IFNULL()
function. Therefore, both functions enable us to replace NULL values with another value.
MySQL has an IF()
function that provides a convenient way to perform a simple “IF/ELSE” operation.
It works similar to a basic IF
/ELSE
statement, in that it allows us to check for a condition, and return a different result depending on whether it’s true or not.
More specifically, if the first argument to the IF()
function is true, the second argument is returned. If it’s not true, the third argument is returned.
In MySQL, NULLIF()
is a flow control function that returns NULL
if both of its arguments are equivalent. Otherwise it returns the first argument.
SQLite provides several functions for inserting, setting, and replacing values in a JSON document. Specifically, it provides json_insert()
, json_set()
, and json_replace()
.
These functions perform similar tasks, and you can sometimes use them interchangeably to a certain point.
But there is definitely a clear difference between each function.
Continue reading