Computed / calculated / virtual / derived columns in PostgreSQL

前端 未结 7 1022
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 06:16

Does PostgreSQL support computed / calculated columns, like MS SQL Server? I can\'t find anything in the docs, but as this feature is included in many other DBMSs I thought

相关标签:
7条回答
  • 2020-11-22 07:02

    I have a code that works and use the term calculated, I'm not on postgresSQL pure tho we run on PADB

    here is how it's used

    create table some_table as
        select  category, 
                txn_type,
                indiv_id, 
                accum_trip_flag,
                max(first_true_origin) as true_origin,
                max(first_true_dest ) as true_destination,
                max(id) as id,
                count(id) as tkts_cnt,
                (case when calculated tkts_cnt=1 then 1 else 0 end) as one_way
        from some_rando_table
        group by 1,2,3,4    ;
    
    0 讨论(0)
提交回复
热议问题