BUG #3822: Nonstandard precedence for comparison operators

Поиск
Список
Период
Сортировка
От Pedro Gimeno
Тема BUG #3822: Nonstandard precedence for comparison operators
Дата
Msg-id 200712171958.lBHJwOBb037317@wwwmaster.postgresql.org
обсуждение исходный текст
Ответы Re: BUG #3822: Nonstandard precedence for comparison operators  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
Список pgsql-bugs
The following bug has been logged online:

Bug reference:      3822
Logged by:          Pedro Gimeno
Email address:      pgsql-001@personal.formauri.es
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

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: bug found in 8.3 beta 3.
Следующее
От: Dimitri Fontaine
Дата:
Сообщение: Re: bug found in 8.3 beta 3.