SQLite insert issue – Error: no such column
Asked Answered
R

2

22

I faced an issue with SQLite (version 3.7.13 if matters).

I created a new table with two columns foo and bar, data type is undefined. When I try to insert numbers, it works fine. But when I insert text, Error: no such column happens.

sqlite> CREATE TABLE test (foo, bar);
sqlite> .tables
test
sqlite> insert into test values (0,1);
sqlite> select * from test;
0|1
sqlite> insert into test values (a,b);
Error: no such column: a

What am I doing wrong?

Thanks.

Rillet answered 22/2, 2014 at 18:47 Comment(0)
F
33

You need to quote strings

insert into test values('a', 'b')
Ferocity answered 22/2, 2014 at 19:0 Comment(1)
Or to use placeholders (e.g., ?) if executing the INSERT in a context that can supply the values more efficiently, such as any embedded use of SQLite (but not the sqlite shell IIRC).Advert
T
0

I got the same error below:

Parse error: no such column: John

Because I used "" for the value John as shown below:

                                  ↓    ↓
INSERT INTO person (name) VALUES ("John");

So, I used '' for the value John as shown below, then the error was solved. *My answer explains it more:

                                  ↓    ↓
INSERT INTO person (name) VALUES ('John');
Terrorist answered 2/10, 2023 at 16:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.