from timetable to mysql database

11 views (last 30 days)
Marco Laiolo
Marco Laiolo on 18 Mar 2024
Commented: Marco Laiolo on 29 Mar 2024 at 13:23
Hi all,
I routinely automatic timetable every X minutes at the end of data processing all with matlab 2023b. I have a mysql database that, currently, i update setting colheaders and alllcolumn variables (double or string or datetime).
I see that sqlwrite don't work with timetable; someone know other function or strategy to write timetable (with colheader) directly in a already created mysql table that have the same column and header name of the timetable?
Thanks
Marco

Answers (1)

Samay Sagar
Samay Sagar on 25 Mar 2024
As mentioned in the MathWorks documentation, “sqlwrite” supports only insertion of “table” data type in a database. However, you can insert a “timetable” in SQL database by employing a workaround by converting your “timetable” to “table” using “timetable2table” function. After converting your timetable to a table, ensure the column names exactly match those in your MySQL table. If your timetable includes a “Time” column (which is automatically created during the conversion), and your MySQL table uses the same column name for time/date data, you're all set. If not, you might need to adjust the column names in your MATLAB table to align with your MySQL schema.
Read more about “timetable2table” and “sqlwrite” here:
  2 Comments
Marco Laiolo
Marco Laiolo on 28 Mar 2024
Thank you very much , Samay...great and it works!
Marco Laiolo
Marco Laiolo on 29 Mar 2024 at 13:23
However, it seems that if in the TABLE there is an already write row (with the same) the command sqlwrite don't work
this tis the message
JDBC Error: Duplicate entry .... for key 'time' (my firstrow after id)
even if I set "unique" on my variable time in mysql db.It's a my problem or someone know this.
Thanks a lot

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!