When using SQLite, we can use the following methods to extract data from a JSON document.
Continue readingCategory: SQLite
Subtract Days from a Date in SQLite
In SQLite, we can use the DATE()
function to subtract one or more days from a date.
For datetime values, we can use the DATETIME()
function.
Add Months to a Date in SQLite
In SQLite, we can use the DATE()
function to add one or more months to a date.
When we’re dealing with datetime values, we can use the DATETIME()
function.
6 Ways to Delete Duplicate Rows that have a Primary Key in SQLite
Below are six examples that delete duplicate rows from a table in SQLite when those rows have a primary key or unique identifier column.
In these instances, the primary key must be ignored when comparing duplicates (due to the fact that primary keys prevent duplicate rows by definition).
Continue reading2 Ways to Enable Word Wrap in SQLite
When using one of SQLite’s tabular output modes, you can enable the --wrap
option in order to limit the width of each column. This can be handy when the data contains long lines of text.
When we do this, we have the option of specifying “word wrap”, so that words don’t get cut off halfway through.
There are two ways to specify word wrap: use --wordwrap on
or its shortcut -ww
.
Difference Between -> and ->> in SQLite
The ->
and ->>
operators were introduced in SQLite version 3.38.0, which was released on 22 February 2022. Both operators are used for extracting subcomponents of JSON. But there’s a subtle difference between them.
Fix Error: “SELECTs to the left and right of UNION do not have the same number of result columns” in SQLite
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.
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.