mariadb-update

Documents MariaDB-specific UPDATE syntax, semantics, and common generation errors.

28|115|Updated Jan 28, 2025
One-click install
npx skills add https://github.com/mariadb-corporation/mariadb-docs --skill mariadb-update-mariadb-corporation
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: mariadb-update
Source: https://github.com/mariadb-corporation/mariadb-docs/tree/main/agent-skills/granular/statements/mariadb-update
Command: npx skills add https://github.com/mariadb-corporation/mariadb-docs --skill mariadb-update-mariadb-corporation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Standard SQL UPDATE knowledge is not enough for MariaDB: its single-table and multi-table forms follow different grammars, assignments evaluate left-to-right, and features like RETURNING, ORDER BY ... LIMIT, and PARTITION apply only to specific forms. This Skill prevents the most common mistakes LLMs make when writing or reviewing UPDATE statements against MariaDB. ## Core Features & Use Cases - Single-table vs multi-table rules: Clarifies which clauses (PARTITION, ORDER BY, LIMIT, RETURNING, FOR PORTION OF) are single-table-only and how multi-table UPDATE joins and writes across tables. - Assignment semantics: Explains left-to-right evaluation, the SIMULTANEOUS_ASSIGNMENT sql_mode for true swaps, and rows-matched-vs-changed reporting. - Version-specific features: Covers UPDATE ... RETURNING with OLD_VALUE() (since 13.0), CTEs before UPDATE (since 12.3), and updates to system-versioned and application-time-period tables. - Use Case: When asked to write a batched update that returns old and new values, produce UPDATE ... ORDER BY ... LIMIT with RETURNING OLD_VALUE(col) instead of incorrectly assuming RETURNING is unsupported or adding LIMIT to a multi-table UPDATE. ## Quick Start Write a MariaDB UPDATE statement that decrements an account balance and returns the old and new balance values.

Frequently Asked Questions about mariadb-update

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use UPDATE ... RETURNING in MariaDB?▼

UPDATE ... RETURNING is supported since MariaDB 13.0 on single-table updates only. Use OLD_VALUE(col) for the pre-update value and a bare column reference for the new value, for example RETURNING id, OLD_VALUE(balance) AS old_balance, balance AS new_balance.

Can I use ORDER BY and LIMIT in a multi-table UPDATE in MariaDB?▼

No. ORDER BY and LIMIT work only on the single-table UPDATE form in MariaDB. The same restriction applies to PARTITION and RETURNING; none of these four clauses are allowed in multi-table UPDATE statements.

Why does UPDATE t SET col1 = col2, col2 = col1 not swap values in MariaDB?▼

Single-table UPDATE evaluates assignments left-to-right, so col2 receives the already-updated col1 value. For simultaneous assignment semantics such as a swap, set sql_mode = 'SIMULTANEOUS_ASSIGNMENT' before running the statement.

Does LOW_PRIORITY affect UPDATE statements on InnoDB tables?▼

No. LOW_PRIORITY only affects table-locking engines such as MyISAM, MEMORY, and Aria. On InnoDB, which uses row-level locking, it has no effect and should be omitted from generated SQL.

Why does MariaDB UPDATE report fewer rows affected than rows matched?▼

UPDATE reports rows changed, not rows matched by the WHERE clause. Rows whose new value equals the old value are matched but not counted as changed; the client-side count also depends on the CLIENT_FOUND_ROWS connection flag.

Can an UPDATE statement reference its own target table in a subquery in MariaDB?▼

Yes. MariaDB allows reading the target table in the UPDATE's own WHERE subquery, such as WHERE id = (SELECT MAX(id) FROM t). Note that DELETE has the opposite restriction and cannot delete from a table read in a subquery.