skip to Main Content

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


  1. Chosen as BEST ANSWER

    The column names have a dot used in them.

    Thus they required to be in following manner

    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'}")
    

    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`


  2. 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 query

    INSERT 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 table events.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search