0

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.

2 Answers 2

1

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");
Sign up to request clarification or add additional context in comments.

Comments

0

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.)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.