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

From Greg Stark
Subject Re: [HACKERS] generated columns
Date
Msg-id CAM-w4HNQ6p6=HsveZpMwprLg=n--DdBqg+0qqmRqbTpu_Mdt1g@mail.gmail.com
Whole thread Raw
In response to [HACKERS] generated columns  (Peter Eisentraut <peter.eisentraut@2ndquadrant.com>)
List pgsql-hackers
On 31 August 2017 at 05:16, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:
> Here is another attempt to implement generated columns.  This is a
> well-known SQL-standard feature, also available for instance in DB2,
> MySQL, Oracle.  A quick example:
>
>   CREATE TABLE t1 (
>     ...,
>     height_cm numeric,
>     height_in numeric GENERATED ALWAYS AS (height_cm * 2.54)
>   );

I only recently discovered we actually already have this feature. Kind of.
stark=# CREATE TABLE t1 (height_cm numeric);
CREATE TABLE
Time: 38.066 ms
stark***=# create function height_in(t t1) returns numeric language
'sql' as 'select t.height_cm * 2.54' ;
CREATE FUNCTION
Time: 1.216 ms
stark***=# insert into t1 values (2);
INSERT 0 1
Time: 10.170 ms
stark***=# select t1.height_cm, t1.height_in from t1;
┌───────────┬───────────┐
│ height_cm │ height_in │
├───────────┼───────────┤
│         2 │      5.08 │
└───────────┴───────────┘
(1 row)

Time: 1.997 ms

Yours looks better :)

-- 
greg

pgsql-hackers by date:

Previous
From: Jeevan Ladhe
Date:
Subject: Re: [HACKERS] Adding support for Default partition in partitioning
Next
From: Michael Paquier
Date:
Subject: Re: [HACKERS] multiple target of VACUUM command