In Mathematics and many programming languages (and I think standard SQL as well), parentheses change precedence (grouping parts to be evaluated first) or to enhance readability (for human eyes).
Equivalent Examples:
SELECT array[1,2] @> array[1]
SELECT (array[1,2]) @> array[1]
SELECT array[1,2] @> (array[1])
SELECT ((array[1,2]) @> (array[1]))
But SELECT 1 = ANY array[1,2]
is a syntax error (!), and SELECT 1 = ANY (array[1,2])
is valid. Why?
OK, because "the manual says so". But what the logic for humans to remember all exceptions?
Is there a guide about it?
I do not understand why (expression)
is the same as expression
in some cases, but not in other cases.
PS1: parentheses are also used as value-list delimiters, as in expression IN (value [, ...])
. But an array is not a value-list, and there does not seem to be a general rule in PostgreSQL when (array expression)
is not the same as array expression
.
Also, I used array as example, but this problem/question is not only about arrays.