Why can't sqlite find this line?

I am using sqlite3. My test table contains two rows (see Image of a screen dump), but I cannot find the second row with

SELECT * FROM test WHERE word = "id"

statement. Why can't sqlite find this line?

(I think the problem is that one attribute is also called "id" because I found that the select statement will work if this attribute is where named id2.)

enter image description here

+4
source share
1 answer

this is due to double quotes, using single quotes will work well:

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
+3

Source: https://habr.com/ru/post/1539826/


All Articles