insert function and fastinsert function

25 views (last 30 days)
Kyle Zarmair
Kyle Zarmair on 15 Jul 2014
Answered: Akshay on 23 Jul 2014
I am trying to insert data from a dataset I created in Matlab into a Microsoft access database. I am currently using the insert ‘function’ to accomplish this; however it is very time consuming due to the fact that I have over a million values to insert. I was wondering if the function ‘fast’ insert would improve the efficiency of my code, and if so, how does the fastinsert function work? I tried using it once before and I keep getting an error message whenever I need to insert a date (I believe it is in the wrong format, but I am not sure).
Thank you.

Answers (1)

Akshay on 23 Jul 2014
• Use datainsert when you want maximum performance, are able to format your input data in a specific way, and your input data is only cell arrays and numeric matrices.
>> datainsert(conn,tablename,columnnames,data)
• Use fastinsert when your input data is a structure, dataset, or table, or you are using a native ODBC database connection.
>> fastinsert(conn,tablename,colnames,exdata)
• Use insert only if datainsert or fastinsert do not work for you and you want to insert a small set of data.
>> insert(conn,tablename,colnames,exdata)
Input data, specified as a MATLAB cell array or numeric matrix. If data is a cell array containing MATLAB dates, times, or timestamps, the dates must be date strings of the form yyyy-mm-dd, times must be time strings of the form HH:MM:SS, and timestamps must be strings of the form yyyy-mm-dd HH:MM:SS.FFF. Any null entries and any NaNs in the cell array must be converted to empty strings before calling datainsert. MATLAB date numbers and NaNs are supported for insert when data is a numeric matrix. Date numbers inserted into database date and time columns convert to java.sql.Date. Any converted date and time data is accurately converted back to the native database format in the target database upon insertion.
Look into the documentation link for Data Export From MATLAB in order to gain more insight about the same

Community Treasure Hunt

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

Start Hunting!

Translated by