Generated Column
Generated Column fields create MySQL generated columns: columns whose value is computed by the database from a MySQL expression applied to other columns in the same row. The database keeps the value up to date automatically whenever the source columns change. The type is listed under Advanced Field Types in the Field type dropdown. Common uses include:
- Address formatting —
CONCAT_WS(', ', street, city, state) - Price calculations —
CONCAT('Total: $', FORMAT((qty * unit_price) + shipping + tax, 2)) - Status determination —
IF(delivery_date IS NOT NULL, 'Complete', 'Pending') - Date extraction —
CONCAT(YEAR(publish_date), ' Q', QUARTER(publish_date)) - String transformation —
UPPER(original_column) - Conditional formatting —
IF(sales > 10000, 'High', 'Low'), or aCASE ... ENDexpression for multiple conditions
Generated columns can only use data from their current row, not from other rows or tables.
Where the field appears
Section titled “Where the field appears”Generated column values are read-only:
- Record list page — can display, sort, and search the field
- Viewer code — display only
- Add/edit pages — not available; the field is never shown in the record editor and no value is accepted from forms
Since other fields can’t react to a value that has no form input, generated columns can’t be selected as the trigger field in another field’s Show if rule.
Field editor options
Section titled “Field editor options”The common options (Field label, Database Field, Field type, Show for, Show if, System field) are covered in Field Editor. The Help tooltip option isn’t available for this type, and there are no validation options.
- MySQL Expression
The MySQL expression that computes the value, entered in a code editor with MySQL syntax highlighting. It’s inserted directly into the column definition:
columnType GENERATED ALWAYS AS (expression) STORED|VIRTUALThe expression isn’t validated by the program; MySQL rejects invalid expressions with an error when the field is saved.
- Storage Type
How MySQL maintains the value:
- Stored (the default, recommended) — values are stored in the database and auto-updated on changes (faster read times, uses disk space)
- Virtual — values are dynamically generated each time they are accessed (slower read times, doesn’t use disk space)
- MySQL column type
The column type the generated value is cast to and stored as. Auto uses
VARCHAR(255)for this field type; choose a preset or custom type for numeric or date expressions.- MySQL indexing
Creates a MySQL column index for the field, which speeds up sorting and some searches but slows down adding and saving records.
In viewers
Section titled “In viewers”Generated columns are real database columns, so they come back in
getRecords() results like any other field:
<?php echo $record['total_price'] ?>They can also be used in the where and orderBy viewer options. There’s
nothing to submit or save; the database computes the value.
Database backups handle generated columns automatically: the backup stores a placeholder instead of the computed values, and MySQL regenerates them on restore.