SQLite’s JSON functions and operators are now enabled by default, starting from SQLite 3.38.0 (released on 22 February 2022).
Relational
Get the First Monday of a Year in SQLite
We 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.
5 Ways to Find Rows that Contain Uppercase Letters in SQL Server
Below are five options for returning rows that contain uppercase letters in SQL Server.
How to Wrap Long Lines of Text in SQLite Results
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.
Format SQLite Results as JSON
It’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.
SQLite SUBSTRING() Explained
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.
How to Format SQLite Results as a Table
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.
4 Tabular Output Modes in SQLite
The SQLite command line interface provides us with several options for outputting our results in tabular format.
These can be set using the .mode command. You simply type .mode followed by the desired output format.
Below are examples of the various tabular modes available in SQLite.
2 Ways to Return the Unix Timestamp in SQLite
The unix timestamp is the number of seconds since 1970-01-01 00:00:00 UTC. SQLite provides us with a couple of ways to get the unix timestamp.
SQLite Renames PRINTF() to FORMAT()
SQLite has introduced the FORMAT() function, which can be used to format strings.
More precisely, it has actually just renamed its SQL PRINTF() function to FORMAT(). The reason is for better compatibility with other DBMSs. The original PRINTF() name is retained as an alias for backwards compatibility.
The FORMAT() function (or its naming) was introduced in SQLite 3.38.0, which was released on 22 February 2022.