mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +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:
@@ -131,6 +131,7 @@ CreateTupleDescCopy(TupleDesc tupdesc)
|
||||
att->atthasdef = false;
|
||||
att->atthasmissing = false;
|
||||
att->attidentity = '\0';
|
||||
att->attgenerated = '\0';
|
||||
}
|
||||
|
||||
/* We can copy the tuple type identification, too */
|
||||
@@ -165,6 +166,7 @@ CreateTupleDescCopyConstr(TupleDesc tupdesc)
|
||||
TupleConstr *cpy = (TupleConstr *) palloc0(sizeof(TupleConstr));
|
||||
|
||||
cpy->has_not_null = constr->has_not_null;
|
||||
cpy->has_generated_stored = constr->has_generated_stored;
|
||||
|
||||
if ((cpy->num_defval = constr->num_defval) > 0)
|
||||
{
|
||||
@@ -247,6 +249,7 @@ TupleDescCopy(TupleDesc dst, TupleDesc src)
|
||||
att->atthasdef = false;
|
||||
att->atthasmissing = false;
|
||||
att->attidentity = '\0';
|
||||
att->attgenerated = '\0';
|
||||
}
|
||||
dst->constr = NULL;
|
||||
|
||||
@@ -300,6 +303,7 @@ TupleDescCopyEntry(TupleDesc dst, AttrNumber dstAttno,
|
||||
dstAtt->atthasdef = false;
|
||||
dstAtt->atthasmissing = false;
|
||||
dstAtt->attidentity = '\0';
|
||||
dstAtt->attgenerated = '\0';
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -456,6 +460,8 @@ equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
|
||||
return false;
|
||||
if (attr1->attidentity != attr2->attidentity)
|
||||
return false;
|
||||
if (attr1->attgenerated != attr2->attgenerated)
|
||||
return false;
|
||||
if (attr1->attisdropped != attr2->attisdropped)
|
||||
return false;
|
||||
if (attr1->attislocal != attr2->attislocal)
|
||||
@@ -476,6 +482,8 @@ equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
|
||||
return false;
|
||||
if (constr1->has_not_null != constr2->has_not_null)
|
||||
return false;
|
||||
if (constr1->has_generated_stored != constr2->has_generated_stored)
|
||||
return false;
|
||||
n = constr1->num_defval;
|
||||
if (n != (int) constr2->num_defval)
|
||||
return false;
|
||||
@@ -638,6 +646,7 @@ TupleDescInitEntry(TupleDesc desc,
|
||||
att->atthasdef = false;
|
||||
att->atthasmissing = false;
|
||||
att->attidentity = '\0';
|
||||
att->attgenerated = '\0';
|
||||
att->attisdropped = false;
|
||||
att->attislocal = true;
|
||||
att->attinhcount = 0;
|
||||
@@ -697,6 +706,7 @@ TupleDescInitBuiltinEntry(TupleDesc desc,
|
||||
att->atthasdef = false;
|
||||
att->atthasmissing = false;
|
||||
att->attidentity = '\0';
|
||||
att->attgenerated = '\0';
|
||||
att->attisdropped = false;
|
||||
att->attislocal = true;
|
||||
att->attinhcount = 0;
|
||||
@@ -853,6 +863,7 @@ BuildDescForRelation(List *schema)
|
||||
TupleConstr *constr = (TupleConstr *) palloc0(sizeof(TupleConstr));
|
||||
|
||||
constr->has_not_null = true;
|
||||
constr->has_generated_stored = false;
|
||||
constr->defval = NULL;
|
||||
constr->missing = NULL;
|
||||
constr->num_defval = 0;
|
||||
|
||||
Reference in New Issue
Block a user