This section is from the "Practical PostgreSQL" book, by John Worsley and Joshua Drake. Also available from Amazon: Practical PostgreSQL.
Table 4-13. Operator Precedence
| Operator / Element | Associativity | Description |
|---|---|---|
:: | left | PostgreSQL style typecast |
[] | left | array element selection |
. | left | table or column name separator |
- | right | unary minus |
^ | left | exponential |
*/% | left | multiplication, division, and modulo |
+- | left | addition, subtraction |
IS | test for TRUE, FALSE, NULL | |
ISNULL | test for NULL | |
NOT NULL | test for NOT NULL | |
any other | left | all other native and user-defined operators |
IN | set membership | |
BETWEEN | containment | |
OVERLAPS | time interval overlap | |
LIKE ILIKE | string pattern matching | |
<> | less than, greater than | |
= | right | equality, assignment |
NOT | right | logical negation |
AND | left | logical conjunction |
OR | left | logical conjunction |
![]() | User Defined Operators |
|---|---|
Operator precedence rules also apply to user-defined operators that have the same name as the built-in operators mentioned above. For example, if you define dot (.) operator for a custom data type, it has the same precedence as the built in dot (.) operator, no matter what you the defined the operator to do. |
For instance, the BETWEEN keyword is used below to display publisher names whose suggested prices are between $8 and $13.50:
SELECT publ_name FROM publish WHERE sugg_price BETWEEN '8.00' AND '13.50';
The column displayed looks like this:
publ_name ----------------- ODG Books Young Readers Reading Rainbow (3 rows)
 
Continue to: