Thread: [SQL] How to use postgresql generated generated always COLUMN ?
DB2 operation: db2 "create table emp(id int,name char(10),salary int,rev_salary integer generated always as (salary*50/100))" [db2inst2@db2 ~]$ db2 "insert into emp(id,name,salary) values(100,'asdf',51100)" [db2inst2@db2 ~]$ db2 "select * from emp" ID NAME SALARY REV_SALARY ----------- ---------- ----------- ----------- 100 asdf 500 250 100 asdf 6600 3300 100 asdf 51100 25550 *How to use postgresql implement?* Thank you! -- View this message in context: http://postgresql.nabble.com/How-to-use-postgresql-generated-generated-always-COLUMN-tp5936872.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com.
On Friday, December 30, 2016, tank.zhang <6220104@qq.com> wrote:
DB2 operation:
db2 "create table emp(id int,name char(10),salary int,rev_salary integer
generated always as (salary*50/100))"
[db2inst2@db2 ~]$ db2 "insert into emp(id,name,salary)
values(100,'asdf',51100)"
[db2inst2@db2 ~]$ db2 "select * from emp"
ID NAME SALARY REV_SALARY
----------- ---------- ----------- -----------
100 asdf 500 250
100 asdf 6600 3300
100 asdf 51100 25550
*How to use postgresql implement?*
You have to use CREATE VIEW. Possibly with insert/update/delete triggers to interact with the backing table.
David J.
Thank you for your help, I under test
------------------ 原始邮件 ------------------
发件人: "David G. Johnston"<david.g.johnston@gmail.com>;
发送时间: 2016年12月31日(星期六) 中午12:52
收件人: "Tank.zhang"<6220104@qq.com>;
抄送: "pgsql-sql@postgresql.org"<pgsql-sql@postgresql.org>;
主题: Re: [SQL] How to use postgresql generated generated always COLUMN ?
DB2 operation:
db2 "create table emp(id int,name char(10),salary int,rev_salary integer
generated always as (salary*50/100))"
[db2inst2@db2 ~]$ db2 "insert into emp(id,name,salary)
values(100,'asdf',51100)"
[db2inst2@db2 ~]$ db2 "select * from emp"
ID NAME SALARY REV_SALARY
----------- ---------- ----------- -----------
100 asdf 500 250
100 asdf 6600 3300
100 asdf 51100 25550
*How to use postgresql implement?*
You have to use CREATE VIEW. Possibly with insert/update/delete triggers to interact with the backing table.
David J.
Thank you for your help, I under test -- View this message in context: http://postgresql.nabble.com/How-to-use-postgresql-generated-generated-always-COLUMN-tp5936872p5936875.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com.