Skip to content

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 formattingCONCAT_WS(', ', street, city, state)
  • Price calculationsCONCAT('Total: $', FORMAT((qty * unit_price) + shipping + tax, 2))
  • Status determinationIF(delivery_date IS NOT NULL, 'Complete', 'Pending')
  • Date extractionCONCAT(YEAR(publish_date), ' Q', QUARTER(publish_date))
  • String transformationUPPER(original_column)
  • Conditional formattingIF(sales > 10000, 'High', 'Low'), or a CASE ... END expression for multiple conditions

Generated columns can only use data from their current row, not from other rows or tables.

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.

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|VIRTUAL

The 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.

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.

Documents CMS Builder 3.83