2
0
mirror of https://git.postgresql.org/git/postgresql.git synced 2025-03-01 19:45:33 +08:00

Even better example for operator precedence mis-parsing.

This commit is contained in:
Peter Eisentraut 2001-02-25 16:05:21 +00:00
parent 2a398726e7
commit 60774e8210

View File

@ -1,5 +1,5 @@
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/syntax.sgml,v 1.40 2001/02/24 18:09:51 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/syntax.sgml,v 1.41 2001/02/25 16:05:21 petere Exp $
--> -->
<chapter id="sql-syntax"> <chapter id="sql-syntax">
@ -905,17 +905,17 @@ sqrt(2)
you will sometimes need to add parentheses when using combinations you will sometimes need to add parentheses when using combinations
of binary and unary operators. For instance of binary and unary operators. For instance
<programlisting> <programlisting>
SELECT 5 ! + 6; SELECT 5 ! - 6;
</programlisting> </programlisting>
will be parsed as will be parsed as
<programlisting> <programlisting>
SELECT 5 ! (+ 6); SELECT 5 ! (- 6);
</programlisting> </programlisting>
because the parser has no idea -- until it is too late -- that because the parser has no idea -- until it is too late -- that
<token>!</token> is defined as a postfix operator, not an infix one. <token>!</token> is defined as a postfix operator, not an infix one.
To get the desired behavior in this case, you must write To get the desired behavior in this case, you must write
<programlisting> <programlisting>
SELECT (5 !) + 6; SELECT (5 !) - 6;
</programlisting> </programlisting>
This is the price one pays for extensibility. This is the price one pays for extensibility.
</para> </para>