0

I keep getting a syntax error when I'm trying to insert new entries into the table but I can't seem to figure out why. For starters here's the .schema:

CREATE TABLE collection (
id int primary key not null,
album text not null,
artist text not null,
year int not null,
cover text 
);

And this is the line I've used to add the entry:

sqlite> insert into collection(115,"houses of the holy","led zeppelin", 1973, "junk");

All the values match up: id int, album text, artist text, year int, cover text. But the terminal just spit out the following syntax error:

Error: near "115": syntax error

I've also tested putting the int values within quotation marks but I just end up with:

Error: near ";": syntax error

Can someone please help me figure out what I'm doing wrong?

1
  • You are using double quotes instead of single quotes. Commented Nov 11, 2016 at 17:23

2 Answers 2

3

You are missing the VALUES keyword.

INSERT INTO table_name
VALUES (value1,value2,value3,...);

For more info see INSERT DOCS

Sign up to request clarification or add additional context in comments.

Comments

1

This syntax is incorrect:

insert into collection(115,"houses of the holy","led zeppelin", 1973, "junk")

First of all, use single-quotes instead of double-quotes:

insert into collection (115, 'houses of the holy', 'led zeppelin', 1973, 'junk')

Aside from that, the query parser is expecting those values to be the column names, and they're not valid as column names. You should be able to simply include the VALUES keyword:

INSERT INTO collection VALUES (115, 'houses of the holy', 'led zeppelin', 1973, 'junk')

Failing that, explicitly specify the column names:

INSERT INTO collection (id, album, artist, year, cover) VALUES (115, 'houses of the holy', 'led zeppelin', 1973, 'junk')

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.