pythondatetimemysql-x-devapi

mysqlx python connector NoSQL can't insert date


I'm using mysqlx XDevAPI for python (NoSQL). I can't insert a date into my table.

table = my_schema.get_table("date_table")
field = "date_field"
insert = table.insert(field)
value = datetime.datetime.now()
insert.values(value)
insert.execute

I get an error:

ValueError: Expected token type 19 at pos 0 but found type 72

I'm presuming it's to do with the date/datetime format but I'm not sure how to find what tokens 19 or 72 are. If I try to insert a string or int I get the same error.


Solution

  • Yes. Like Rui said, Connector/Python doesn't support Python object conversion in the X DevAPI, you need to convert the datetime to a string format before inserting.