【问题标题】:How to add a generated column to a PostgreSQL table with Liquibase?如何使用 Liquibase 将生成的列添加到 PostgreSQL 表中?
【发布时间】:2022-06-15 02:16:33
【问题描述】:

我想使用 Liquibase 将生成的列 https://www.postgresql.org/docs/current/ddl-generated-columns.html 添加到我的 PostgreSQL 表中。我已经尝试了所有想到的方法,甚至是:

 - 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

导致

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"]

【问题讨论】:

  • PostgreSQL 对事情可能很挑剔。 [ALTER TABLE] (postgresql.org/docs/current/sql-altertable.html) 的 Oracle 文档应该有一些额外的上下文来帮助解决错误。如果仍然存在,请回复 ALTER TABLE 代码以便我们进行审核。

标签: postgresql liquibase


【解决方案1】:

有一个小时的时间再做一次。这样就完成了工作:

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

【讨论】:

    猜你喜欢
    • 2020-09-18
    • 2022-11-11
    • 2021-10-10
    • 1970-01-01
    • 2013-09-01
    • 2021-10-05
    • 2019-08-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多