Re: [HACKERS] generated columns

Peter Eisentraut <peter.eisentraut@2ndquadrant.com>

From: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>, Pavel Stehule <pavel.stehule@gmail.com>, Sergei Kornilov <sk@zsrv.org>, Jaime Casanova <jaime.casanova@2ndquadrant.com>
Date: 2019-02-27T07:05:02Z
Lists: pgsql-hackers
On 2019-02-26 06:30, Michael Paquier wrote:
> +   if (attgenerated)
> +   {
> +       /*
> +        * Generated column: Dropping anything that the generation expression
> +        * refers to automatically drops the generated column.
> +        */
> +       recordDependencyOnSingleRelExpr(&colobject, expr, RelationGetRelid(rel),
> +                                       DEPENDENCY_AUTO,
> +                                       DEPENDENCY_AUTO, false);
> +   }
> A CCI is not necessary I think here, still the recent thread about
> automatic dependencies with identity columns had a much similar
> pattern...

Yeah, worth taking another look.

> 
> +           else if (generated[0] == ATTRIBUTE_GENERATED_VIRTUAL)
> +               default_str = psprintf("generated always as (%s)", PQgetvalue(res, i, attrdef_col));
> Nit: I would add VIRTUAL instead of relying on the default option.

I suppose we'll decide that when the virtual columns are actually added.
 I see your point.

> Another thing I was thinking about: could it be possible to add a
> sanity check in sanity_check.sql so as a column more that one
> field in attidentity, attgenerated and atthasdef set at the same time?

There is something like that at the top of
src/test/regress/sql/generated.sql.  I can expand that.  But it only
covers the tests.  For run time checks, you'd want something like
pg_catcheck.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


Commits

  1. Generated columns

  2. Add walreceiver API to get remote server version

  3. Add pg_partition_tree to display information about partitions

  4. pg_restore: Augment documentation for -N option

  5. Change delimiter used for display of NextXID