Outdated Version

You are viewing an older version of this section. View current production version.


Replace data in a table, or if the data does not match, inserts it. The syntax for REPLACE is identical to INSERT. Only the semantics of replacement differ.

REPLACE [INTO] tbl_name [(col_name,...)]
    {VALUES | VALUE} (expr,...),(...),...

REPLACE [INTO] tbl_name [(col_name,...)]
    SELECT ...

REPLACE [INTO] tbl_name
    SET col_name=expr, ...
  • MemSQL supports constants, DEFAULT, or nullary builtins such as NOW(), RAND(), or UNIX_TIMESTAMP() for expressions (expr) for REPLACEs.
  • Arithmetic expressions are not currently supported in the VALUES clause.
  • REPLACE queries will fail if maximum_table_memory limit has been reached.
  • REPLACE queries will fail if there are concurrent ALTER TABLE , CREATE INDEX , or DROP INDEX statements running on the table.
  • This command must be run on the master aggregator or a child aggregator node (see Node Requirements for MemSQL Commands).
memsql> REPLACE INTO mytbl (seq) VALUE (2);
Query OK, 1 row affected (1.99 sec)