Re: [HACKERS] generated columns
От | Greg Stark |
---|---|
Тема | Re: [HACKERS] generated columns |
Дата | |
Msg-id | CAM-w4HNQ6p6=HsveZpMwprLg=n--DdBqg+0qqmRqbTpu_Mdt1g@mail.gmail.com обсуждение исходный текст |
Ответ на | [HACKERS] generated columns (Peter Eisentraut <peter.eisentraut@2ndquadrant.com>) |
Список | 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 по дате отправления: