Re: generated columns
Greg Stark <stark@mit.edu>
From: Greg Stark <stark@mit.edu>
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2017-08-31T13:44:13Z
Lists: 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
Commits
-
Generated columns
- fc22b6623b6b 12.0 landed
-
Add walreceiver API to get remote server version
- 69039fda837d 12.0 landed
-
Add pg_partition_tree to display information about partitions
- d5eec4eefde7 12.0 cited
-
pg_restore: Augment documentation for -N option
- 2fe42baf7c1a 12.0 cited
-
Change delimiter used for display of NextXID
- 59a884e9854c 9.6.0 cited