Re: [HACKERS] Re: [HACKERS] generated columns - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: [HACKERS] Re: [HACKERS] generated columns
Date
Msg-id b5c27634-1d44-feba-7494-ce5a31f914ca@2ndquadrant.com
Whole thread Raw
In response to Re: [HACKERS] Re: [HACKERS] generated columns  (Joe Conway <mail@joeconway.com>)
Responses Re: [HACKERS] Re: [HACKERS] generated columns
List pgsql-hackers
On 12/30/17 16:04, Joe Conway wrote:
> +<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>
> 
> Question -- when the "stored" kind of generated column is implemented,
> will the immutable restriction be relaxed? I would like, for example, be
> able to have a stored generated column that executes now() whenever the
> row is written/rewritten.

That restriction is from the SQL standard, and I think it will stay.
The virtual vs. stored choice is an optimization, but not meant to
affect semantics.  For example, you might want to automatically
substitute a precomputed generated column into an expression, but that
will become complicated and confusing if the expression is not
deterministic.

Another problem with your example is that a stored generated column
would only be updated if a column it depends on is updated.  So a column
whose generation expression is just now() would never get updated.

Maybe some of this could be relaxed at some point, but we would have to
think it through carefully.  For now, a trigger would still be the best
implementation for your use case, I think.

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


pgsql-hackers by date:

Previous
From: Ivan Kartyshov
Date:
Subject: [Patch] Checksums for SLRU files
Next
From: Tom Lane
Date:
Subject: Re: What does Time.MAX_VALUE actually represent?