If you’re getting “Error: in prepare, SELECTs to the left and right of UNION do not have the same number of result columns…” in when trying to use the UNION
operator in SQLite, it’s because one of the SELECT
statements is returning more columns than the other.
Category: SQLite
Calculate the Number of Seconds Since a Particular Date/Time in SQLite
If you need to calculate the number of seconds that have passed since a given date and time, you can use the UNIXEPOCH()
function.
Note that this function was introduced in SQLite 3.38.0, so it will only work if you’re using SQLite 3.38.0 or later.
Continue readingAdd Days to a Date in SQLite
In SQLite, we can use the DATE()
function to add a given number of days to a date.
If we’re dealing with datetime values, we can use the DATETIME()
function.
nullvalue: Show NULL Values in SQLite
When using the SQLite command line interface (CLI), by default, whenever a query returns a null value, the output is the empty string (''
).
We can change this by using the -nullvalue
command line option when launching SQLite.
We can also use the .nullvalue
dot command if we’re already in the SQLite CLI.
JSON Functions & Operators in SQLite (Full List)
Below is a full list of JSON functions and JSON operators available in SQLite.
Continue readingHow to Convert to Uppercase in SQLite
In SQLite we can use the upper()
function to convert lowercase characters to uppercase.
2 Ways to Return the Julian Day in SQLite
Here are two methods for returning the Julian Day in SQLite.
The Julian Day is the fractional number of days since noon in Greenwich on November 24, 4714 B.C. It’s the continuous count of days since the beginning of the Julian period, and is used primarily by astronomers, and in software for easily calculating elapsed days between two events.
Continue readingSQLite ->> Operator
In SQLite, the ->>
operator extracts a subcomponent from a JSON document and returns an SQL representation of that subcomponent.
The ->>
operator was first introduced in SQLite version 3.38.0 (released on 22 February 2022).
SQLite -> Operator
In SQLite, the ->
operator extracts a subcomponent from a JSON document and returns a JSON representation of that subcomponent.
The ->
operator was first introduced in SQLite version 3.38.0 (released on 22 February 2022).
SQLite JSON_TREE()
In SQLite, json_tree()
is a table-valued function that walks the JSON value provided as its first argument and returns a table consisting of one row for each array element or object member.
We provide the JSON value as an argument when we call the function.
Continue reading