MySQL includes some inbuilt functions that can be used to create JSON values, such as JSON arrays, JSON objects, or a quoted string literal.
Here are seven functions that allow us to create JSON values in MySQL.
Continue readingMySQL includes some inbuilt functions that can be used to create JSON values, such as JSON arrays, JSON objects, or a quoted string literal.
Here are seven functions that allow us to create JSON values in MySQL.
Continue readingBelow is a list of the JSON functions and operators available in MySQL.
Continue readingIn MySQL, the JSON_SCHEMA_VALIDATION_REPORT()
function validates a JSON document against a JSON schema and returns a report of the outcome of that validation. The report is returned as a JSON document.
If the document is valid, only one field is returned: "valid" : true
. If the document is not valid, a more extensive report is provided.
A common task when working with numbers is to format them to a certain amount of decimal places. Two decimal places seems to be the most common format, but we can format to any number of decimal places we want. MySQL provides us with a number of functions that can help us achieve this.
Below are seven functions that can be used to format a number to two decimal places in MySQL.
Continue readingIn MySQL, the JSON_SCHEMA_VALID()
function validates a JSON document against a JSON schema. It returns true (1
) if the document is valid, and false (0
) if it is not.
In MySQL, JSON_OVERLAPS()
is a function that tests whether or not two JSON documents have any key-value pairs or array elements in common.
The function returns true (1
) if the documents have any key-value pairs or array elements in common, and false (0
) if they don’t.
The JSON_OVERLAPS()
function was added in MySQL 8.0.17.
In MySQL, JSON_MERGE()
is a deprecated function that merges two or more JSON documents and returns the result.
It was deprecated in MySQL 8.0.3 and is subject to removal in a future release.
Fortunately, the JSON_MERGE_PRESERVE()
function was added in MySQL 8.0.3 as a synonym for JSON_MERGE()
, and it therefore does the same thing that JSON_MERGE()
does/did.
Therefore, instead of using JSON_MERGE()
, use JSON_MERGE_PRESERVE()
instead.
Alternatively, you can use JSON_MERGE_PATCH()
, which performs an RFC 7396 compliant merge of two or more JSON documents, without preserving members having duplicate keys.
In MySQL, JSON_TABLE()
is a built-in function that converts JSON data into a relational form.
In other words, it lets you return a JSON document as a table.
The JSON_TABLE()
function was introduced in MySQL 8.0.
In MySQL, CAST()
is a built in function that converts a value to another data type. It takes a value of one type and returns a value of the specified type.
You provide the value as an argument when you call the function, as well as the type that you’d like it converted to.
CAST()
works similar to CONVERT()
, except that the syntax used is slightly different.
In MySQL, the LAST_INSERT_ID()
function returns the first automatically generated value successfully inserted for an AUTO_INCREMENT
column as a result of the most recently executed INSERT
statement.
It can also be called with an argument, in which case, it returns the value of the expression and the next call to LAST_INSERT_ID()
will return the same value.