当我尝试在将MySql表中的布尔值实现为ruby脚本之前手动更新它时,我得到了一个匹配值,但没有更改:
UPDATE calls SET ended = NOT ended WHERE incoming_Cid = '1234567890';Query OK, 0 rows affected (0.00 sec)Rows matched: 1 Changed: 0 Warnings: 0
除非我弄错了,在我看来,这是正确的语法。
我查看了有关这个问题的其他线程(翻转布尔值),比如这里。
有什么更好的方法来实现这一点呢?
发布于 2013-08-08 18:27:24
这是否有效:
UPDATE calls set ended = !ended WHERE incoming_Cid = '1234567890';发布于 2013-08-08 18:45:56
您的ended值很可能是一个SQL NULL值。null值的逻辑not仍然为null,因此DB正确地报告了“无更改”,因为ended中的值没有变化--它最初是null,现在仍然是null:
mysql> create table foo (x boolean);
mysql> insert into foo values (null);
Query OK, 1 row affected (0.04 sec)
mysql> update foo set x=not x;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> update foo set x=not x;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0注意Changed: 0。但是,一旦将x重置为非空值:
mysql> update foo set x=true;
Query OK, 1 row affected (0.06 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update foo set x=not x;
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0行立即开始更改。
https://stackoverflow.com/questions/18133174
复制相似问题