我有一个 Liquibase 迁移 XML 文件,它使用 datetime
创建列类型。
<createTable tableName="foo">
<column name="bar" type="datetime"/>
</createTable>
令我惊愕的是,今天我意识到这些是在没有时区的情况下创建的(在 PostgreSQL 中为 timestamp without time zone
),而且似乎没有任何您可以使用的 Liquibase 类型会给您一个 timestamp with time zone
.除了拥有 <sql>
之外,还有什么办法可以解决这个问题吗?在最初创建表后像这样更改表的 block :
<sql>
alter table foo alter column bar type timestamp with time zone;
</sql>
谢谢。
最佳答案
TL;DR:使用带时区的时间戳
:
<column name="bar" type="timestamp with time zone"/>
Liquibase datetime
将自动转换为目标数据库的时间戳类型,但无法指定时区。
Liquibase 将接受timestamp with time zone
并将其作为 native 类型传递(无转换),但由于它是 SQL 标准类型,因此无论如何它都会被任何标准数据库(包括 PostgreSQL)接受.
timestamptz
是 PostgreSQL 特定的相同数据类型的缩写。它不是可移植的。
关于postgresql - 从 Liquibase XML 在 PostgreSQL 中创建带时区的时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55617051/