Sqlite Literals

SQLite: Literals

This SQLite post explains how to use literals (string, number, date, time, and boolean literals) in SQLite with examples.

Description

In SQLite, a literal is the same as a constant. We'll cover several types of literals - string literals, number literals, date and time literals and boolean literals.

String Literals

String literals are always surrounded by single quotes (') or double quotes ("). For example:

Example Explanation
'AODBA.com' String literal with single quotes
'Tech on the Net' String literal with single quotes
"AODBA.com" String literal with double quotes
"Tech on the Net" String literial with double quotes

Number Literals

Number literals can be either positive or negative numbers that are exact or floating point values. If you do not specify a sign, then a positive number is assumed. Here are some examples of valid number literals:

Example Explanation
72 Integer literal with no sign (positive sign is assumed)
+72 Integer literal with positive sign
-72 Integer literal with negative sign
72e-04 Floating point literal
72.607 Decimal literal

Date and Time Literals

Date and time literals can be expressed as strings. Here are some examples of valid date and time literals:

Example Explanation
'2015-04-27' Date literal formatted as 'YYYY-MM-DD'
'2015-04-27 11:44:23' Datetime literal formatted as 'YYYY-MM-DD HH:MM:SS'

Boolean Literals

There are no boolean literals in SQLite, instead, boolean literals are stored as numeric values. Here are some examples of valid boolean literals:

Example Explanation
1 Equivalent to TRUE (stored as a number)
0 Equivalent to FALSE (stored as a number)