mirror of
https://github.com/postgres/postgres.git
synced 2025-12-21 05:21:08 +03:00
Generated columns
This is an SQL-standard feature that allows creating columns that are computed from expressions rather than assigned, similar to a view or materialized view but on a column basis. This implements one kind of generated column: stored (computed on write). Another kind, virtual (computed on read), is planned for the future, and some room is left for it. Reviewed-by: Michael Paquier <michael@paquier.xyz> Reviewed-by: Pavel Stehule <pavel.stehule@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/b151f851-4019-bdb1-699e-ebab07d2f40a@2ndquadrant.com
This commit is contained in:
@@ -42,7 +42,8 @@ CREATE FOREIGN TABLE [ IF NOT EXISTS ] <replaceable class="parameter">table_name
|
||||
{ NOT NULL |
|
||||
NULL |
|
||||
CHECK ( <replaceable class="parameter">expression</replaceable> ) [ NO INHERIT ] |
|
||||
DEFAULT <replaceable>default_expr</replaceable> }
|
||||
DEFAULT <replaceable>default_expr</replaceable> |
|
||||
GENERATED ALWAYS AS ( <replaceable>generation_expr</replaceable> ) STORED }
|
||||
|
||||
<phrase>and <replaceable class="parameter">table_constraint</replaceable> is:</phrase>
|
||||
|
||||
@@ -258,6 +259,30 @@ CHECK ( <replaceable class="parameter">expression</replaceable> ) [ NO INHERIT ]
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>GENERATED ALWAYS AS ( <replaceable>generation_expr</replaceable> ) STORED</literal><indexterm><primary>generated column</primary></indexterm></term>
|
||||
<listitem>
|
||||
<para>
|
||||
This clause creates the column as a <firstterm>generated
|
||||
column</firstterm>. The column cannot be written to, and when read it
|
||||
will be computed from the specified expression.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The keyword <literal>STORED</literal> is required to signify that the
|
||||
column will be computed on write. (The computed value will be presented
|
||||
to the foreign-data wrapper for storage and must be returned on
|
||||
reading.)
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The generation expression can refer to other columns in the table, but
|
||||
not other generated columns. Any functions and operators used must be
|
||||
immutable. References to other tables are not allowed.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><replaceable class="parameter">server_name</replaceable></term>
|
||||
<listitem>
|
||||
|
||||
Reference in New Issue
Block a user