Author: paul
Date: 2008-10-03 20:17:49 +0200 (Fri, 03 Oct 2008)
New Revision: 11977
Log:
r34464@frost: paul | 2008-10-03 13:18:38 -0500
Unsigned integer subtraction that results in negative value wraps around
to large integer value
(Bug#38512)
Modified:
trunk/refman-4.1/data-types.xml
trunk/refman-5.0/data-types.xml
trunk/refman-5.1/data-types.xml
trunk/refman-6.0/data-types.xml
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 4767c598-dc10-0410-bea0-d01b485662eb:/mysqldoc-local/mysqldoc/trunk:35828
7d8d2c4e-af1d-0410-ab9f-b038ce55645b:/mysqldoc-local/mysqldoc:34463
b5ec3a16-e900-0410-9ad2-d183a3acac99:/mysqldoc-local/mysqldoc/trunk:14218
bf112a9c-6c03-0410-a055-ad865cd57414:/mysqldoc-local/mysqldoc/trunk:33554
+ 4767c598-dc10-0410-bea0-d01b485662eb:/mysqldoc-local/mysqldoc/trunk:35828
7d8d2c4e-af1d-0410-ab9f-b038ce55645b:/mysqldoc-local/mysqldoc:34464
b5ec3a16-e900-0410-9ad2-d183a3acac99:/mysqldoc-local/mysqldoc/trunk:14218
bf112a9c-6c03-0410-a055-ad865cd57414:/mysqldoc-local/mysqldoc/trunk:33554
Modified: trunk/refman-4.1/data-types.xml
===================================================================
--- trunk/refman-4.1/data-types.xml 2008-10-03 18:17:43 UTC (rev 11976)
+++ trunk/refman-4.1/data-types.xml 2008-10-03 18:17:49 UTC (rev 11977)
Changed blocks: 1, Lines Added: 34, Lines Deleted: 0; 1722 bytes
@@ -2570,6 +2570,40 @@
</para>
<para>
+ Subtraction between integer values, where one is of type
+ <literal>UNSIGNED</literal>, produces an unsigned result by
+ default. If the result would otherwise have been negative, it
+ becomes the maximum integer value. If the
+ <literal>NO_UNSIGNED_SUBTRACTION</literal> SQL mode is enabled,
+ the result is negative.
+ </para>
+
+<programlisting>
+mysql> <userinput>SET SQL_MODE = '';</userinput>
+mysql> <userinput>SELECT CAST(0 AS UNSIGNED) - 1;</userinput>
++-------------------------+
+| CAST(0 AS UNSIGNED) - 1 |
++-------------------------+
+| 18446744073709551615 |
++-------------------------+
+
+mysql> <userinput>SET SQL_MODE =
'NO_UNSIGNED_SUBTRACTION';</userinput>
+mysql> <userinput>SELECT CAST(0 AS UNSIGNED) - 1;</userinput>
++-------------------------+
+| CAST(0 AS UNSIGNED) - 1 |
++-------------------------+
+| -1 |
++-------------------------+
+</programlisting>
+
+ <para>
+ If the result of such an operation is used to update an
+ <literal>UNSIGNED</literal> integer column, the result is clipped
+ to the maximum value for the column type, or clipped to 0 if
+ <literal>NO_UNSIGNED_SUBTRACTION</literal> is enabled.
+ </para>
+
+ <para>
Conversions that occur due to clipping are reported as
<quote>warnings</quote> for <literal>ALTER TABLE</literal>,
<literal>LOAD DATA INFILE</literal>,
<literal>UPDATE</literal>,
Modified: trunk/refman-5.0/data-types.xml
===================================================================
--- trunk/refman-5.0/data-types.xml 2008-10-03 18:17:43 UTC (rev 11976)
+++ trunk/refman-5.0/data-types.xml 2008-10-03 18:17:49 UTC (rev 11977)
Changed blocks: 2, Lines Added: 39, Lines Deleted: 3; 2437 bytes
@@ -2651,9 +2651,9 @@
SQL mode in effect at the time. For example, if no restrictive
modes are enabled, MySQL clips the value to the appropriate
endpoint of the range and stores the resulting value instead.
- However, if the mode is set to <literal>TRADITIONAL</literal>,
- MySQL rejects a value that is out of range with an error, and the
- insert fails, in accordance with the SQL standard.
+ However, if strict SQL mode is enabled, MySQL rejects a value that
+ is out of range with an error, and the insert fails, in accordance
+ with the SQL standard.
</para>
<para>
@@ -2669,6 +2669,42 @@
</para>
<para>
+ Subtraction between integer values, where one is of type
+ <literal>UNSIGNED</literal>, produces an unsigned result by
+ default. If the result would otherwise have been negative, it
+ becomes the maximum integer value. If the
+ <literal>NO_UNSIGNED_SUBTRACTION</literal> SQL mode is enabled,
+ the result is negative.
+ </para>
+
+<programlisting>
+mysql> <userinput>SET SQL_MODE = '';</userinput>
+mysql> <userinput>SELECT CAST(0 AS UNSIGNED) - 1;</userinput>
++-------------------------+
+| CAST(0 AS UNSIGNED) - 1 |
++-------------------------+
+| 18446744073709551615 |
++-------------------------+
+
+mysql> <userinput>SET SQL_MODE =
'NO_UNSIGNED_SUBTRACTION';</userinput>
+mysql> <userinput>SELECT CAST(0 AS UNSIGNED) - 1;</userinput>
++-------------------------+
+| CAST(0 AS UNSIGNED) - 1 |
++-------------------------+
+| -1 |
++-------------------------+
+</programlisting>
+
+ <para>
+ If the result of such an operation is used to update an
+ <literal>UNSIGNED</literal> integer column, the result is clipped
+ to the maximum value for the column type, or clipped to 0 if
+ <literal>NO_UNSIGNED_SUBTRACTION</literal> is enabled. If strict
+ SQL mode is enabled, an error occurs and the column remains
+ unchanged.
+ </para>
+
+ <para>
Conversions that occur due to clipping when MySQL is not operating
in strict mode are reported as warnings for <literal>ALTER
TABLE</literal>, <literal>LOAD DATA INFILE</literal>,
Modified: trunk/refman-5.1/data-types.xml
===================================================================
--- trunk/refman-5.1/data-types.xml 2008-10-03 18:17:43 UTC (rev 11976)
+++ trunk/refman-5.1/data-types.xml 2008-10-03 18:17:49 UTC (rev 11977)
Changed blocks: 2, Lines Added: 39, Lines Deleted: 3; 2437 bytes
@@ -2500,9 +2500,9 @@
SQL mode in effect at the time. For example, if no restrictive
modes are enabled, MySQL clips the value to the appropriate
endpoint of the range and stores the resulting value instead.
- However, if the mode is set to <literal>TRADITIONAL</literal>,
- MySQL rejects a value that is out of range with an error, and the
- insert fails, in accordance with the SQL standard.
+ However, if strict SQL mode is enabled, MySQL rejects a value that
+ is out of range with an error, and the insert fails, in accordance
+ with the SQL standard.
</para>
<para>
@@ -2518,6 +2518,42 @@
</para>
<para>
+ Subtraction between integer values, where one is of type
+ <literal>UNSIGNED</literal>, produces an unsigned result by
+ default. If the result would otherwise have been negative, it
+ becomes the maximum integer value. If the
+ <literal>NO_UNSIGNED_SUBTRACTION</literal> SQL mode is enabled,
+ the result is negative.
+ </para>
+
+<programlisting>
+mysql> <userinput>SET SQL_MODE = '';</userinput>
+mysql> <userinput>SELECT CAST(0 AS UNSIGNED) - 1;</userinput>
++-------------------------+
+| CAST(0 AS UNSIGNED) - 1 |
++-------------------------+
+| 18446744073709551615 |
++-------------------------+
+
+mysql> <userinput>SET SQL_MODE =
'NO_UNSIGNED_SUBTRACTION';</userinput>
+mysql> <userinput>SELECT CAST(0 AS UNSIGNED) - 1;</userinput>
++-------------------------+
+| CAST(0 AS UNSIGNED) - 1 |
++-------------------------+
+| -1 |
++-------------------------+
+</programlisting>
+
+ <para>
+ If the result of such an operation is used to update an
+ <literal>UNSIGNED</literal> integer column, the result is clipped
+ to the maximum value for the column type, or clipped to 0 if
+ <literal>NO_UNSIGNED_SUBTRACTION</literal> is enabled. If strict
+ SQL mode is enabled, an error occurs and the column remains
+ unchanged.
+ </para>
+
+ <para>
Conversions that occur due to clipping when MySQL is not operating
in strict mode are reported as warnings for <literal>ALTER
TABLE</literal>, <literal>LOAD DATA INFILE</literal>,
Modified: trunk/refman-6.0/data-types.xml
===================================================================
--- trunk/refman-6.0/data-types.xml 2008-10-03 18:17:43 UTC (rev 11976)
+++ trunk/refman-6.0/data-types.xml 2008-10-03 18:17:49 UTC (rev 11977)
Changed blocks: 2, Lines Added: 39, Lines Deleted: 3; 2437 bytes
@@ -2499,9 +2499,9 @@
SQL mode in effect at the time. For example, if no restrictive
modes are enabled, MySQL clips the value to the appropriate
endpoint of the range and stores the resulting value instead.
- However, if the mode is set to <literal>TRADITIONAL</literal>,
- MySQL rejects a value that is out of range with an error, and the
- insert fails, in accordance with the SQL standard.
+ However, if strict SQL mode is enabled, MySQL rejects a value that
+ is out of range with an error, and the insert fails, in accordance
+ with the SQL standard.
</para>
<para>
@@ -2517,6 +2517,42 @@
</para>
<para>
+ Subtraction between integer values, where one is of type
+ <literal>UNSIGNED</literal>, produces an unsigned result by
+ default. If the result would otherwise have been negative, it
+ becomes the maximum integer value. If the
+ <literal>NO_UNSIGNED_SUBTRACTION</literal> SQL mode is enabled,
+ the result is negative.
+ </para>
+
+<programlisting>
+mysql> <userinput>SET SQL_MODE = '';</userinput>
+mysql> <userinput>SELECT CAST(0 AS UNSIGNED) - 1;</userinput>
++-------------------------+
+| CAST(0 AS UNSIGNED) - 1 |
++-------------------------+
+| 18446744073709551615 |
++-------------------------+
+
+mysql> <userinput>SET SQL_MODE =
'NO_UNSIGNED_SUBTRACTION';</userinput>
+mysql> <userinput>SELECT CAST(0 AS UNSIGNED) - 1;</userinput>
++-------------------------+
+| CAST(0 AS UNSIGNED) - 1 |
++-------------------------+
+| -1 |
++-------------------------+
+</programlisting>
+
+ <para>
+ If the result of such an operation is used to update an
+ <literal>UNSIGNED</literal> integer column, the result is clipped
+ to the maximum value for the column type, or clipped to 0 if
+ <literal>NO_UNSIGNED_SUBTRACTION</literal> is enabled. If strict
+ SQL mode is enabled, an error occurs and the column remains
+ unchanged.
+ </para>
+
+ <para>
Conversions that occur due to clipping when MySQL is not operating
in strict mode are reported as warnings for <literal>ALTER
TABLE</literal>, <literal>LOAD DATA INFILE</literal>,
| Thread |
|---|
| • svn commit - mysqldoc@docsrva: r11977 - in trunk: . refman-4.1 refman-5.0 refman-5.1 refman-6.0 | paul.dubois | 3 Oct |