为什么sqlite不能找到这一行?
发布时间:2020-12-12 18:54:35 所属栏目:百科 来源:网络整理
导读:我正在使用sqlite3.我的测试表包含两行(参见屏幕转储图像),但我找不到使用的第二行 SELECT * FROM test WHERE word=”id” 声明.为什么sqlite找不到那行? (我认为问题是一个属性也被称为“id”,因为我发现如果那个名为id2的属性改为,则select语句会起作用.)
我正在使用sqlite3.我的测试表包含两行(参见屏幕转储图像),但我找不到使用的第二行
声明.为什么sqlite找不到那行? (我认为问题是一个属性也被称为“id”,因为我发现如果那个名为id2的属性改为,则select语句会起作用.) 解决方法这是因为双引号,使用单引号将使其正常工作:sqlite> create table test ( id integer primary key autoincrement,word text not null unique on conflict ignore ); sqlite> insert into test values (1,'xxx'); sqlite> insert into test values (2,'id'); sqlite> select * from test; 1|xxx 2|id sqlite> select * from test where word = "id"; sqlite> select * from test where word = 'id'; 2|id 这是因为id是当前模式中列的名称,因为您可以在列名称周围使用双引号,sqlite认为您在谈论列,而不是给出字符串.即: sqlite> insert into test values (3,3); sqlite> select * from test where word = "id"; 3|3 sqlite> select * from test where word = id; 3|3 如果你可以在列上使用双引号,那是因为空格在列名中是合法的: sqlite> create table test2 ( "foo bar" integer ); sqlite> .schema test2 CREATE TABLE test2 ( "foo bar" integer ); sqlite> insert into test2 values (42); sqlite> select * from test2; 42 sqlite> select * from test2 where "foo bar" = 42; 42 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |