I am trying to insert data using the following query
INSERT INTO events(
'_id',
'id',
'_kafka.topic',
'_kafka.partition',
'_kafka.offset',
'_kafka.timestamp',
'_kafka.key',
'_kafka.simulated',
'_kafka.consumed'
)
VALUES(
"{'$oid': '5daa639e4176a8d0301beb0c'}",
'0',
'Events_227_v3',
'2',
'22938980',
"{'$date': '2019-10-19T01:15:10.355Z'}",
"b'0'",
'False',
"{'$date': '2019-10-19T01:15:10.913Z'}"
)
Error message
`#1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ”_id’, ‘id’, ‘_kafka.topic’, ‘_kafka.partition’, ‘_kafka.offset’, ‘_kafka.timest’ at line 1
What is causing this error?
2
Answers
The column names have a dot used in them.
Thus they required to be in following manner
Usage of ` symbol was required alongwith the column names.
For example, if column name is col.name then in the query it should be like `col.name`
On
Insert
the column name shouldn’t enclosed using single'
or double quotes"
.Instead mention just the column name or use back ticks (`).
Suppose you have table like
events
and_kafka
And when executing the below
Insert
queryINSERT INTO events(id, _kafka.topic) VALUES( '1', 'Events_227_v3')
It will throw an error
Unknown column '_kafka.topic' in 'field list'
since the column
topic
doesn’t exists in the tableevents
.