How SQLite Ltrim() Works

The SQLite ltrim() function trims whitespace or other characters from the left of a string.

More precisely, it returns a copy of the string that you provide as an argument, with the left part trimmed of either whitespace, or other characters that you specify.

Read more

How to Change the Command Line Prompt in SQLite

If you’ve ever used the SQLite command line shell, you’re probably familiar with the default command line prompt. Actually, there are two prompts:

  • The default main prompt looks like this: sqlite>
  • The default continuation prompt looks like this: ...>

If you don’t like these prompts, you can always change them with the .prompt dot command.

This article provides a quick demonstration on how to change these prompts.

Read more

How the LIKE Operator Works in SQLite

In SQLite, you can use the LIKE operator in your queries to do a pattern matching comparison.

For example, you can add it to your WHERE clause in order to return only rows that match a given pattern.

However, adding it to the WHERE clause isn’t the only way you can use the LIKE operator. You can also use it to return a boolean value.

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

Tweak your Avg() Results in SQLite with the DISTINCT Keyword

If you know about the avg() function in SQLite, you’re probably aware that it returns the average of all non-NULL X within a group.

But did you know you can add the DISTINCT keyword to this function?

If you add the DISTINCT keyword, avg() will calculate its results based on distinct values only. This is essentially the same as removing duplicate values and then calculating the average on the remaining values.

Read more