The following bug has been logged online: Bug reference: 3822 Logged by: Pedro Gimeno Email address: [EMAIL PROTECTED] PostgreSQL version: 8.2.5 Operating system: Any Description: Nonstandard precedence for comparison operators Details:
The operators <>, <= and >= are expected to have the same precedence as =, < and >, but according to the docs (and matching actual behaviour) they have the same precedence as e.g. ||. This leads to surprises such as this one: SELECT 'a' = 'b' || 'c'; SELECT 'a' < 'b' || 'c'; SELECT 'a' > 'b' || 'c'; return either FALSE or TRUE, but SELECT 'a' <> 'b' || 'c'; SELECT 'a' <= 'b' || 'c'; SELECT 'a' >= 'b' || 'c'; give an error because they are equivalent to: SELECT ('a' <> 'b') || 'c'; SELECT ('a' <= 'b') || 'c'; SELECT ('a' >= 'b') || 'c'; respectively, which try to concatenate a boolean value with 'c'. On the other hand, the following work as expected: SELECT 'b' || 'c' <> 'a'; SELECT 'b' || 'c' >= 'a'; SELECT 'b' || 'c' <= 'a'; That's because, having || and e.g. <> the same priority, they are evaluated left-to-right. Of course the same applies to != since it is converted to <>. Now being picky, the precedence of < and > should be the same as that of = (for comparison, not for assignment), which makes a difference in rare cases like this: SELECT false = false < false; which in PostgreSQL returns true instead of false because it is equivalent to this: SELECT false = (false < false); -- Pedro Gimeno ---------------------------(end of broadcast)--------------------------- TIP 6: explain analyze is your friend