Re: Precedence of standard comparison operators

Поиск
Список
Период
Сортировка
От Geoff Winkless
Тема Re: Precedence of standard comparison operators
Дата
Msg-id CAEzk6fd-SOSaEDF76PM8U6jxpLi-SYynNjZEsk3MjfScLuZsvw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Precedence of standard comparison operators  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
On 10 August 2015 at 16:31, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Pavel Stehule <pavel.stehule@gmail.com> writes:
>> On Sun, Aug 09, 2015 at 08:06:11PM -0400, Tom Lane wrote:
>>> So yeah, I do think that getting a syntax error if you don't use
>>> parentheses is the preferable behavior here.

> If we raise a syntax error, then there should be very informative message,

Yeah, it would sure be nice to throw something better than "syntax error".
But I've looked at bison's facilities for that, and they're pretty bad.
I'm not sure there's much we can do short of moving to some other parser
generator tool, which would be a Large Undertaking ... and I don't know
of any arguably-better tool anyway.

I would say that anyone who's tricksy enough to be using boolean logic in the way you describe would be expected to have enough nouse about them to either a) know what the precedences are or b) know that their lack of knowledge means they should sprinkle their code with
​brackets
.​ 

Returning a syntax error for something that isn't actually an error in syntax is a poor showing. 
Are we to start
​expecting 
syntax errors when people use comparison operators on
​NULLable​
 
​​
columns
without a COALESCE 
because the comparison might do something they don't expect
​ if they haven't tested their code with NULL values
?

IMO using a = b < c as described is unnecessarily* horrid, whichever way you mean it, and will only produce the sort of unreadability that generates errors in the long run anyway (even if you understand it, chances are the next poor sap reading your code won't) and deserves code that breaks, especially if you're the sort of person who uses it without fully understanding it.

(*Unnecessarily because there are clearer constructs - CASE springs to mind - that do the same thing without the associated unreadability and/or ambiguity)

Geoff

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

Предыдущее
От: Pavel Stehule
Дата:
Сообщение: Re: PL/pgSQL, RAISE and error context
Следующее
От: Alvaro Herrera
Дата:
Сообщение: Re: [PROPOSAL] VACUUM Progress Checker.