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.

Continue reading

Fix “ERROR: each INTERSECT query must have the same number of columns” in PostgreSQL

When using PostgreSQL’s INTERSECT operator, if you encounter an error that reads “ERROR: each INTERSECT query must have the same number of columns“, it’s because there’s a mismatch in the number of columns returned by the queries on either side of the INTERSECT operator.

The way to fix this is to ensure that both SELECT statements return the same number of columns.

Continue reading

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.

Continue reading