From: | Greg Stark <stark(at)mit(dot)edu> |
---|---|
To: | Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com> |
Cc: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: generated columns |
Date: | 2017-08-31 13:44:13 |
Message-ID: | CAM-w4HNQ6p6=HsveZpMwprLg=n--DdBqg+0qqmRqbTpu_Mdt1g@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 31 August 2017 at 05:16, Peter Eisentraut
<peter(dot)eisentraut(at)2ndquadrant(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Paquier | 2017-08-31 14:09:20 | Re: multiple target of VACUUM command |
Previous Message | Jeevan Ladhe | 2017-08-31 12:53:22 | Re: Adding support for Default partition in partitioning |