平塚です。
On Tue, 12 May 2009 00:49:07 +0900
mao <mao@xxxxx> wrote:
> mysql 5でやった場合は、0から1を引くと4294967295になってしまいます。
> これを0にする方法はありませんでしょうか?
使っている人をみたことがないのでおすすめするわけではないんですが、
NO_UNSIGNED_SUBTRACTIONを使うとできます。
mysql> create table t (c1 int unsigned);
Query OK, 0 rows affected (0.18 sec)
mysql> insert into t values (0);
Query OK, 1 row affected (0.00 sec)
mysql> set sql_mode = 'NO_UNSIGNED_SUBTRACTION';
Query OK, 0 rows affected (0.00 sec)
mysql> update t set c1 = c1 - 1;
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 1
mysql> select * from t;
+------+
| c1 |
+------+
| 0 |
+------+
1 row in set (0.00 sec)
<参考>
http://dev.mysql.com/doc/refman/4.1/en/news-4-0-2.html
Added NO_UNSIGNED_SUBTRACTION to the set of flags that may be specified
with the --sql-mode option for mysqld. It disables unsigned arithmetic
rules when it comes to subtraction. (This makes MySQL 4.0 behave more
like 3.23 with UNSIGNED columns).
--
平塚貞夫 hiratsuka.sadao@xxxxx