gpt4 book ai didi

mysql - 无法更新 mysql 表中的位

转载 作者:行者123 更新时间:2023-11-29 06:01:56 26 4
gpt4 key购买 nike

我有一个包含以下 sql 的表:

CREATE TABLE `event` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`created_date` datetime DEFAULT NULL,
`modified_date` datetime DEFAULT NULL,
`description` varchar(2000) NOT NULL,
`enabled` bit(1) NOT NULL,
`end_date_time` datetime NOT NULL,
`image_url` varchar(255) NOT NULL,
`start_date_time` datetime NOT NULL,
`title` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
)

当我使用具有插入权限的用户运行以下命令时,我得到以下结果:

mysql> insert into event (description, enabled, end_date_time, image_url, start_date_time, title) values ('asdf', 1, NOW(), 'asdf', NOW(), 'asf');

为什么我无法更新“已启用”标志?

mysql> select * from event;
+----+---------------------+---------------------+-------------+---------+---------------------+-----------+---------------------+-------+
| id | created_date | modified_date | description | enabled | end_date_time | image_url | start_date_time | title |
+----+---------------------+---------------------+-------------+---------+---------------------+-----------+---------------------+-------+
| 1 | 2017-05-29 17:10:39 | 2017-05-29 17:10:39 | DESCRIPTION | | 2017-05-29 17:10:39 | URL | 2017-05-29 17:10:39 | TITLE |
| 2 | NULL | NULL | asdf | | 2017-05-29 22:00:32 | asdf | 2017-05-29 22:00:32 | asf |
+----+---------------------+---------------------+-------------+---------+---------------------+-----------+---------------------+-------+
2 rows in set (0.00 sec)

mysql>


注意

mysql> select if((select enabled from event where id = 2), 'true', 'false');
+---------------------------------------------------------------+
| if((select enabled from event where id = 2), 'true', 'false') |
+---------------------------------------------------------------+
| true |
+---------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> update event set enabled = 0;
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0

mysql> select if((select enabled from event where id = 2), 'true', 'false');
+---------------------------------------------------------------+
| if((select enabled from event where id = 2), 'true', 'false') |
+---------------------------------------------------------------+
| false |
+---------------------------------------------------------------+
1 row in set (0.00 sec)

mysql>

最佳答案

您设置得很好。只是当它显示时,它显示为\x01,这是一个不可打印的字符。

(如果您运行 SELECT * FROM events WHERE enabled=1 会发生什么?)

如果您对此列使用 tinyint(1) 而不是 bit(1),事情可能会更直观。

关于mysql - 无法更新 mysql 表中的位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44252386/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com