# Method Mysql.SqlTable()->insert_or_update()

Method insert_or_update

  `int insert_or_update(mapping(string:mixed) record, void|int(0..2) clear_other_fields)`

Description

  Insert a record into the table using an INSERT ... ON DUPLICATE KEY UPDATE command: In case record conflicts with an existing record then it is updated like the update function would do, otherwise it is inserted like insert would do.

  If id_col is set and that column doesn't exist in record then the field is added to the mapping with the value that the inserted or updated record got.

Returns

  The value of the id_col column for the new or updated record. Zero is returned if there is no id_col column.

Note

  This function isn't atomic if clear_other_fields is unset and record contains fields which do not correspond to real columns, i.e. if the prop_col column may need to be updated.