2

MySQL gives me syntax error for a simple query but I don't see any error. If you guys find any please help.

insert into cast(sid,celeb_id,type,name,prior)
  values(30,1,1,'James Keziah Delaney',2)

It gives sql syntax error near cast.

2 Answers 2

5

The main cause of this error is that there is a function Cast in mysql.

It look like to call the cast() function.

You can choose one of the solutions to solve it.

  1. add ` to contain cast table name

look like this.

insert into `cast`(sid,celeb_id,type,name,prior) values(30,1,1,'James Keziah Delaney',2)

sqlfiddle

  1. add a space between cast and ( let mysql know you did't want to execute Cast method. thank for @Barmar remind.

Note:

I would suggest you don't give the table name from keyword or function name.

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

3 Comments

It's not listed on the reserved words page you linked to.
You can also just put a space between cast and (. Then it doesn't look like a function call.
Correct on the reserved work @Barmar but is is on dev.mysql.com/doc/refman/8.0/en/func-op-summary-ref.html as a function
0

You can't insert into cast(). It requires a list of column names.

2 Comments

Based on the syntax, it looks like the table name is cast.
Not a great choice for a table name. 8-)

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.