gpt4 book ai didi

sql - 无法通过一个列名选择现有行

转载 作者:行者123 更新时间:2023-12-03 18:39:57 24 4
gpt4 key购买 nike

我有一个带名为users的表的sqlite3数据库。该表具有名为activation_token的列,其类型为VARCHAR(255)

该表中只有一行,用

900395b3d2faf7d553f719df666d1a755fb7aef0


我希望以下内容返回该记录,但没有输出:

SELECT * FROM users 
WHERE activation_token = '900395b3d2faf7d553f719df666d1a755fb7aef0';


实际上,该命令的输出确实使我感到困惑

SELECT activation_token FROM users 
where activation_token != '900395b3d2faf7d553f719df666d1a755fb7aef0';

900395b3d2faf7d553f719df666d1a755fb7aef0


我究竟做错了什么?

.schema users的输出,以验证我输入的列名正确:

CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "email" varchar(255), "crypted_password" varchar(255), "salt" varchar(255), "created_at" datetime, "updated_at" datetime, "remember_me_token" varchar(255) DEFAULT NULL, "remember_me_token_expires_at" datetime DEFAULT NULL, "activation_state" varchar(255) DEFAULT NULL, "activation_token" varchar(255) DEFAULT NULL, "activation_token_expires_at" datetime DEFAULT NULL, "reset_password_token" varchar(255) DEFAULT NULL, "reset_password_token_expires_at" datetime DEFAULT NULL, "reset_password_email_sent_at" datetime DEFAULT NULL, "last_login_at" datetime DEFAULT NULL, "last_logout_at" datetime DEFAULT NULL, "last_activity_at" datetime DEFAULT NULL, "failed_logins_count" integer DEFAULT 0, "lock_expires_at" datetime DEFAULT NULL);
CREATE INDEX "index_users_on_activation_token" ON "users" ("activation_token");
CREATE INDEX "index_users_on_last_logout_at_and_last_activity_at" ON "users" ("last_logout_at", "last_activity_at");
CREATE INDEX "index_users_on_remember_me_token" ON "users" ("remember_me_token");


SELECT '->' || activation_token || '<-' FROM users;的输出以验证是否没有空格:

->900395b3d2faf7d553f719df666d1a755fb7aef0<-

最佳答案

要检查activation_token列中的实际值,我建议以下内容:

SELECT '%' || activation_token || '%' FROM users WHERE 1=1;


如果值的开头或结尾处有空格,则百分号应使其明显。

关于sql - 无法通过一个列名选择现有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7382093/

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