The maximum length of an operator string is technically 31, though in practice you will rarely see an operator string longer than two or three characters. Some other restrictions on operators are:

$ and :

The dollar sign and colon are only allowed within an operator name with multiple characters, but not in a single character operator name.

-- and /*

This combination of symbols cannot appear anywhere within an operator name because it is viewed as the start of a comment.

+ or -

A multiple character operator name can only end with a minus (-) or a plus (+) sign when the name also contains at least one of the following characters: ~ ! @ # $ % ^ ' & | ? :

For instance, ^- is allowed, but <- is not acceptable. This restriction on names gives PostgreSQL the ability to parse syntactically valid SQL queries without having to require spaces to separate tokens.

When using user-defined operator names, you should consider making it a habit to separate adjacent operators with a space to clearly define what you want to do. For instance, if you defined a left-unary operator named ^, you can safely specify:

 A+ ^B 

In contrast, the following will be unrecognizable, and cause parsing errors:


If whitespace is omitted between the operator names, the parser will look for a concatenated name string including the operator symbols, rather than two separate operator names.

You should note that the two operators combinations are equivalent: != and <> . This is because the != operator is internally mapped to the <> operator.