A parsing question

Поиск
Список
Период
Сортировка
Искать

A parsing question

От:
Michael Nolan <htfoot@gmail.com>
Дата:
Recently I was typing in a query in PG 10.4.

What I MEANT to type was:   Where xyz >= 2400

What I actually typed was:  Where xyz >- 2400

The latter was interpreted as 'where xyz > -2400', but I'm wondering if it shouldn't have thrown an error on an unrecognized operator '>-'

Thoughts?
--
Mike Nolan

Re: A parsing question

От:
"David G. Johnston" <david.g.johnston@gmail.com>
Дата:
On Wed, Jun 3, 2020 at 3:41 PM Michael Nolan <htfoot@gmail.com> wrote:
Recently I was typing in a query in PG 10.4.

What I MEANT to type was:   Where xyz >= 2400

What I actually typed was:  Where xyz >- 2400

The latter was interpreted as 'where xyz > -2400', but I'm wondering if it shouldn't have thrown an error on an unrecognized operator '>-'

From the syntax section of the documentation:

A multiple-character operator name cannot end in + or -, unless the name also contains at least one of these characters:

~ ! @ # % ^ & | ` ?

For example, @- is an allowed operator name, but *- is not. This restriction allows PostgreSQL to parse SQL-compliant queries without requiring spaces between tokens.

David J.

Re: A parsing question

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Michael Nolan  writes:
> Recently I was typing in a query in PG 10.4.
> What I MEANT to type was:   Where xyz >= 2400

> What I actually typed was:  Where xyz >- 2400

> The latter was interpreted as 'where xyz > -2400', but I'm wondering if it
> shouldn't have thrown an error on an unrecognized operator '>-'

No, we do it that way intentionally, because the SQL standard requires us
to parse such cases in this way.  The CREATE OPERATOR man page has some
details about what is and isn't a valid operator name ... and '>-' isn't
one.  (The rules there probably look a bit bizarre, but the intention
is to ensure that operators found in the SQL spec can be parsed without
requiring spaces between them.)

			regards, tom lane


FAQ