I wrote:
> I see another problem with this patch: the code added to
> ATExecDropColumn is a crude hack.  It doesn't work anyway since this is
> not the only possible way for columns to be dropped (another one that
> comes to mind immediately is DROP TYPE ... CASCADE).  The only correct
> way to handle things is to let the dependency mechanism do it.

Actually, the whole question of dependencies for generated columns
probably needs some thought.  What should happen if a function or
operator used in a GENERATED expression gets dropped?  The result
for a normal column's default expression is that the default expression
goes away, but the column is still there.  I suspect we don't want
that for a GENERATED column --- it would then be effectively a plain

Along the same lines, is ALTER COLUMN DROP DEFAULT a legal operation
on a generated column?  What about just replacing the expression with

Before you get too excited about making generated columns disappear
automatically in all these cases, consider that dropping a column
is not something to be done lightly --- it might contain irreplaceable

On second thought maybe the right approach is just to allow the default
expression to be dropped the same as it would be for an ordinary column,
and to make sure that if a GENERATED column doesn't (currently) have a
default, it is treated the same as an ordinary column.

This leads to the further thought that maybe GENERATED is not a property
of a column at all, but of its default (ie, it should be stored in
pg_attrdef not pg_attribute, which would certainly make the patch less
messy).  AFAICS plain GENERATED merely indicates that the default
expression can depend on other columns, which is certainly a property
of the default --- you could imagine ALTER COLUMN SET DEFAULT GENERATED
AS ... to make a formerly plain column into a GENERATED one.  I'm not
entirely sure about ALWAYS though.

                        regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at


Reply via email to