In SQLite, the json_array()
function returns a well-formed JSON array based on its arguments.
The function accepts zero or more arguments, and each argument becomes an element in the resulting array.
Continue readingIn SQLite, the json_array()
function returns a well-formed JSON array based on its arguments.
The function accepts zero or more arguments, and each argument becomes an element in the resulting array.
Continue readingThe SQLite json_object()
function returns a well-formed JSON object based on its arguments.
The function accepts zero or more pairs of arguments and returns a well-formed JSON object based on those arguments.
Continue readingIn SQLite, the json()
function converts raw text that looks like JSON into actual JSON.
We pass a JSON string as an argument when we call the function. The json()
function then checks that the argument is a valid JSON string and returns a minified version of that JSON string. If the argument is not a well-formed JSON string, then an error is thrown.
However, the json()
function was not designed to test whether or not a value is valid JSON. To do that, use the json_valid()
function instead.
Starting with SQLite version 3.38.0 (released on 22 February 2022), we can now use the ->
and ->>
operators to extract subcomponents of JSON documents.
The aim with these operators is to be compatible with the equivalent MySQL and PostgreSQL operators.
Continue readingSQLite’s JSON functions and operators are now enabled by default, starting from SQLite 3.38.0 (released on 22 February 2022).
Continue readingWe can use SQLite’s DATE()
function to return the date of the first instance of a given day of a given year. Therefore, we can use it to return the first Monday of a given year. We can also use it to return the first Tuesday, Wednesday, Thursday, Friday, etc.
We can use DATETIME()
if we want a datetime value to be returned.
If you’re using one of SQLite’s tabular output modes, you might find yourself battling with long lines of text that result in all subsequent columns being pushed out far to the right. This can cause you to have to keep scrolling sideways as you peruse the data.
Fortunately, there’s an easy fix.
Continue readingIt’s possible to output query results as a JSON document when using the SQLite command line interface.
We can do this with the json
output mode.
We can also use SQLite functions like json_object()
and/or json_array()
to return query results as a JSON document.
In SQLite, substring()
is an alias for substr()
.
It returns a substring from a string, based on a given starting location within the string. Two arguments are required, and a third optional argument is accepted.
The substring()
naming was introduced in SQLite 3.34.0, which was released on 1st December 2020. The reason that the substring()
syntax was introduced was for compatibility with SQL Server.
SQLite has a number of tabular output modes. One of these is called table
mode.
Below is an example of using table
mode to output SQLite’s query results as a table.