Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

E0013 generated-column-write

INSERT or UPDATE gives a value to a generated column.

CodeNameCategoryDefault
E0013generated-column-writecorrectnesserror

What it reports

An INSERT gives a value other than DEFAULT to a generated column (GENERATED ALWAYS AS (expr) STORED, MySQL / SQLite AS (expr)), or UPDATE sets one. In PostgreSQL the same holds for identity columns declared GENERATED ALWAYS AS IDENTITY. The database computes these values itself and rejects the statement.

The examples on this page also use this table:

CREATE TABLE line_items (
  id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  quantity INT NOT NULL,
  unit_price NUMERIC(10, 2) NOT NULL,
  amount NUMERIC(12, 2) GENERATED ALWAYS AS (quantity * unit_price) STORED
);

Example

INSERT INTO line_items (quantity, unit_price, amount) VALUES (2, 9.50, 19.00);
error[E0013]: Column 'amount' is a generated column: INSERT can't give it a value
  --> q.sql:1:47
    |
  1 | INSERT INTO line_items (quantity, unit_price, amount) VALUES (2, 9.50, 19.00);
    |                                               ^^^^^^
    = help: Leave the column out of the INSERT, or give it DEFAULT

Fixed:

INSERT INTO line_items (quantity, unit_price) VALUES (2, 9.50);

Notes

DEFAULT is always allowed, and so are GENERATED BY DEFAULT AS IDENTITY columns. Generated columns may be left out of an INSERT even when they are NOT NULL (E0008 doesn't report them). SQLite doesn't count generated columns in an INSERT without a column list.

Configuring

# sqlsift.toml
[rules]
generated-column-write = "warn"   # or "off"

Or for a single line: -- sqlsift:disable E0013. The examples use the schema on the Rules page.