How iif() Works in SQLite

In SQLite, iif() is a conditional function that returns the second or third argument based on the evaluation of the first argument.

It’s logically equivalent to CASE WHEN X THEN Y ELSE Z END.

iif() is an abbreviation for Immediate IF.

The iif() function was introduced in SQLite 3.32.0, which was released on 22 May 2020.

Read more

What is a Generated Column?

Some database management systems (DBMSs) include a feature called generated columns.

Also known as “computed columns”, generated columns are similar to a normal column, except that a generated column’s value is derived from an expression that computes values from other columns.

In other words, a generated column’s value is computed from other columns.

Read more

How ON CONFLICT Works in SQLite

SQLite has the ON CONFLICT clause that allows you to specify how to handle constraint conflicts. It applies to UNIQUE, NOT NULL, CHECK, and PRIMARY KEY constraints (but not FOREIGN KEY constraints).

There are five possible options you can use with this clause:

  • ABORT
  • FAIL
  • IGNORE
  • REPLACE
  • ROLLBACK

This article provides examples and an explanation of each of these options.

The ON CONFLICT clause is used in CREATE TABLE statements, but it can also be used when inserting or updating data by replacing ON CONFLICT with OR.

Read more

What is SQLite?

SQLite is a widely-used lightweight, embedded relational database management system (RDBMS).

SQLite is a C-language library that implements a small, fast, self-contained, high-reliability, full-featured, SQL database engine. SQLite is largely SQL standards compliant, and it is fully ACID compliant.

Read more

How AUTOINCREMENT Works in SQLite

In SQLite, an AUTOINCREMENT column is one that uses an automatically incremented value for each row that’s inserted into the table.

There are a couple of ways you can create an AUTOINCREMENT column:

  • You can create it implicitly when you define the column as INTEGER PRIMARY KEY.
  • You can create it explicitly with the AUTOINCREMENT keyword. One downside of this method is that it uses extra CPU, memory, disk space, and disk I/O overhead.

Both methods cause the column to use an incrementing value each time a new row is inserted with NULL in that column.

However, there are some subtle differences between how each method works.

Read more