简体   繁体   中英

How to add a generated column to a PostgreSQL table with Liquibase?

I'd like to add a generated column https://www.postgresql.org/docs/current/ddl-generated-columns.html to my PostgreSQL table with Liquibase. I've tried everything that came to my mind, even something like:

 - column:
     computed: true
     name: final_blows_death_ratio numeric GENERATED ALWAYS AS (CASE deaths WHEN 0 THEN 'NaN' ELSE TRUNC(final_blows::NUMERIC / deaths, 2) END) STORED

which results in

Unexpected error running Liquibase: ERROR: syntax error at end of input
  Position: 195 [Failed SQL: (0) ALTER TABLE public.overwatch_player_performances ADD "final_blows_death_ratio numeric GENERATED ALWAYS AS (CASE deaths WHEN 0 THEN 'NaN' ELSE TRUNC(final_blows::NUMERIC / deaths, 2) END) STORED"]

Got an hour to work on it again. This gets the job done:

- addColumn:
    columns:
      - column:
          name: column_name
          type: >
            column_type GENERATED ALWAYS AS (your expression here) STORED
          constraints:
            nullable: true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM