mirror of
https://github.com/postgres/postgres.git
synced 2025-08-31 17:02:12 +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:
@@ -243,6 +243,24 @@
|
||||
operation, and so they can return <symbol>NULL</symbol>.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Some considerations apply for generated
|
||||
columns.<indexterm><primary>generated column</primary><secondary>in
|
||||
triggers</secondary></indexterm> Stored generated columns are computed after
|
||||
<literal>BEFORE</literal> triggers and before <literal>AFTER</literal>
|
||||
triggers. Therefore, the generated value can be inspected in
|
||||
<literal>AFTER</literal> triggers. In <literal>BEFORE</literal> triggers,
|
||||
the <literal>OLD</literal> row contains the old generated value, as one
|
||||
would expect, but the <literal>NEW</literal> row does not yet contain the
|
||||
new generated value and should not be accessed. In the C language
|
||||
interface, the content of the column is undefined at this point; a
|
||||
higher-level programming language should prevent access to a stored
|
||||
generated column in the <literal>NEW</literal> row in a
|
||||
<literal>BEFORE</literal> trigger. Changes to the value of a generated
|
||||
column in a <literal>BEFORE</literal> trigger are ignored and will be
|
||||
overwritten.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
If more than one trigger is defined for the same event on the same
|
||||
relation, the triggers will be fired in alphabetical order by
|
||||
|
Reference in New Issue
Block a user