Reputation: 1974
I'm just starting out in SQLite and have run into my first error.
What I'm trying to do is to create a table in my database with data from a text file, but I get these errors saying:
Error: near line 4: no such column: ’Microsoft’
Error: near line 5: no such column: ‘Apple’
Error: near line 6: no such column: ‘Youtube’
Error: near line 7: no such column: ‘Facebook’
My text file looks like this, I just manipulated a previously created table:
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE stockprices (id integer primary key, price text);
INSERT INTO "stockprices" VALUES(22,’Microsoft’);
INSERT INTO "stockprices" VALUES(33,‘Apple’);
INSERT INTO "stockprices" VALUES(55, ‘Youtube’);
INSERT INTO "stockprices" VALUES(44, ‘Facebook’);
COMMIT;
And I get these errors by using the command:
.read ./Documents/sqlite3Files/stockprices.sql
I was under the impression that you could just create a new table from a already saved one?
Any suggestions on how to do this correctly would be appreciated.
Upvotes: 0
Views: 655
Reputation: 180060
In SQL, strings must be quoted with single ASCII quotes ('
).
Your .sql file contains typographic quotes (‘
), probably because some word processor tried to be helpful.
Replace all ‘
with '
.
(Note: Double quotes ("
) should be used only for table/column names.)
Upvotes: 0
Reputation: 1084
The errors you see are because the quote you are using for string values are not what sqlite expects. You can try with " (ascii code 34) as follows:
CREATE TABLE stockprices (id integer primary key, price text);
INSERT INTO "stockprices" VALUES(22,"Microsoft");
INSERT INTO "stockprices" VALUES(33,"Apple");
INSERT INTO "stockprices" VALUES(55,"Youtube");
INSERT INTO "stockprices" VALUES(44,"Facebook");
Upvotes: 1