| Components | All | New | MacOS | Windows | Linux | iOS | ||||
| Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old | |
Matrix.InsertOrUpdateRecords
Insert or updates a lot of records queried from a database.
| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
| Matrix | 16.1 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
MBS( "Matrix.InsertOrUpdateRecords"; MatrixRef; InsertFileName; InsertTableName; FieldNames; KeyFieldMapping ) More
Parameters
| Parameter | Description | Example |
|---|---|---|
| MatrixRef | The matrix reference number. | $matrix |
| InsertFileName | The file name of where the insert table is inside. Can be empty to look for the table in all files. | Get(FileName) |
| InsertTableName | The name of the table to insert record into. Can be ID of table, so we lookup name by ID. Can be result of GetFieldName() function as we remove field name automatically. |
"Assets" |
| FieldNames | A list of field names for the insert. Empty entries in the list are ignored. Can be ID of field, so we lookup name by ID. Can be result of GetFieldName() function as we remove table name automatically. |
"Model" |
| KeyFieldMapping | The list of field names with index to map keys. Please specify a list of key name=key index. The key name is the name of the field in the insert table and the index gives zero-based position in result set from SELECT query in 6th parameter. Field order in source and destination does not need to be the same. |
ID=0 |
Result
Returns OK or error.
Description
Insert or updates a lot of records queried from a database.Similar to FM.InsertOrUpdateRecordQuery, but taking records from a matrix.
Copy can be from one database to other or within same database. Also from one table to other or within a table. Due to passing in new field names, you can even rearrange values from one column to other while copying. In the SQL you can use functions for sums or join data from several tables together to fill a new table. Filename parameters can be empty.
Use FM.ExecuteSQL.LastErrorMessage and FM.ExecuteSQL.LastError to see error message.
Reports an error if field name list doesn't match column count of the stored SQL result.
Please remove from SQL statement and field names all fields which are globals or unstored calculations.
For inserting records from other database (e.g. MySQL), please use SQL.InsertRecords function.
You can specify fields and table via IDs and the plugin will lookup them for you at runtime. Table IDs and table names must be unique across all open files for this to work correctly.
You can use GetFieldName() function to query field names and the plugin removes the table prefix with :: in the field name before passing it to SQL engine.
Examples
Load records into a matrix and insert/update to other table:
Set Variable [ $SelectSQL ; Value: "SELECT PrimaryKey, TextField, NumberField, DateField, TimeField, TimestampField, ContainerField, Description FROM Source" ]
Set Variable [ $InsertFields ; Value: "Key¶TextField¶NumberField¶DateField¶TimeField¶TimestampField¶ContainerField¶Description" ]
#
Set Variable [ $sql ; Value: MBS("Matrix.NewWithSQL"; Get(FileName); $SelectSQL) ]
#
If [ MBS("IsError") ]
Show Custom Dialog [ "Error: " & $sql ]
Else
Set Variable [ $result ; Value: MBS("Matrix.InsertOrUpdateRecords"; $sql; Get(FileName); "Dest"; $InsertFields; "Key=0") ]
If [ MBS("IsError") ]
Show Custom Dialog [ "Error: " & $result ]
Else
Show Custom Dialog [ "Records updated." ; $result ]
End If
End If
#
Set Variable [ $r ; Value: MBS("Matrix.Release"; $sql) ]
Set Variable [ $InsertFields ; Value: "Key¶TextField¶NumberField¶DateField¶TimeField¶TimestampField¶ContainerField¶Description" ]
#
Set Variable [ $sql ; Value: MBS("Matrix.NewWithSQL"; Get(FileName); $SelectSQL) ]
#
If [ MBS("IsError") ]
Show Custom Dialog [ "Error: " & $sql ]
Else
Set Variable [ $result ; Value: MBS("Matrix.InsertOrUpdateRecords"; $sql; Get(FileName); "Dest"; $InsertFields; "Key=0") ]
If [ MBS("IsError") ]
Show Custom Dialog [ "Error: " & $result ]
Else
Show Custom Dialog [ "Records updated." ; $result ]
End If
End If
#
Set Variable [ $r ; Value: MBS("Matrix.Release"; $sql) ]
See also
- FM.InsertOrUpdateRecord
- FM.InsertOrUpdateRecord2
- FM.InsertOrUpdateRecord3
- FM.InsertOrUpdateRecord4
- FM.SQL.InsertOrUpdateRecords
- IsError
- Matrix.InsertOrUpdateRecordsToSQL
- Matrix.NewWithSQL
- SQL.InsertOrUpdateRecords
- SQL.InsertRecords
Release notes
- Version 16.1
- Added FM.SQL.InsertOrUpdateRecords and Matrix.InsertOrUpdateRecords functions.
- Added FM.SQL.InsertOrUpdateRecordsToSQL and Matrix.InsertOrUpdateRecordsToSQL functions.
Blog Entries
This function checks for a license.
Created 23th January 2026, last changed 12nd February 2026