Unary Expressions

Unary operators are the simplest type of expression operator. They take a single (or unitary) parameter expression and modify or alter that expression in some way. In all cases, if the parameter expression is NULL, the operator will also return NULL.

image with no caption

SQLite supports the following unary expression operators:

- Sign negation

A unary negative sign will invert the sign of a numeric expression, and is equivalent to being multiplied by ‒1. Positive expressions become negative, while negative expressions become positive. Any non-NULL parameter expression will be converted into a numeric type before the conversion.

+ Positive sign

Logically, this operator is a nonoperation. It does not force numbers to be positive (use the abs() SQL function for that), it simply maintains the current sign. It can be used with any datatype, including text and BLOB types, and will simply return the value, without conversion.

Although this operator does not alter the value of the parameter expression, the result expression is still considered a “computed” expression. Applying this operator to a column identifier will dissociate the resulting expression from the source table. This alters the way the query optimizer considers the expression. For example, the optimizer won’t attempt to use any indexes associated with the source column or a computed result column.

~ Bit inversion

Inverts or negates all ...

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.