Appendix D. SQLite SQL Expression Reference

Like most computer languages, SQL has a fairly flexible expression syntax that can be used to combine and compute values. Nearly any time that an SQL command requires a result, conditional, or other value, a full expression can be used to express that value.

In addition to literal values, basic arithmetic operations, and function calls, expressions also contain column references, and complex operator expressions. These can be combined and mixed to create some fairly complex expressions and behaviors.

Many times an expression is used to define a conditional, such as which rows are returned in a result. In these contexts, an expression need only return a logical true or false value. In other situations, such as defining the result set of a SELECT statement, expressions that return diverse values are more appropriate.

The following sections each cover a specific category of expression. Although the different types of operators and expression formats have been divided up to make their descriptions easier to organize, remember that any expression type can be used in any other expression type.

If you want to play around with an operator or expression construction outside of a larger query, remember that you can execute any arbitrary expression by simply placing it in a SELECT statement:

SELECT 1 + 1;

This is extremely useful for testing specific conditions, value conversions, and other situations that may be causing problems within some larger SQL ...

Get Using SQLite now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.