Extending Operators

PostgreSQL uses operators as the method by which data comparisons or aggregations are done. There are three general classes of PostgreSQL operators: left unary, right unary, and binary.

Binary operators are perhaps the most common. In essence, an operator is binary when it will sit between two separate data types (for example, 21 > 20). A classic example of a binary data type is the greater-than symbol (>); it sits between two data elements and returns a Boolean value from the evaluation of each element. Even more basic is the addition operator (+), which sums the values on each side and returns a result (for example, 2 + 3 returns 5).

Unary operators only accept data from one side, hence the names left unary or right unary. ...

Get PostgreSQL Essential Reference 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.