PostgreSQL - 如何创建 table 并将值保存为 PST 时间戳?

PostgreSQL - How to create a table with value saved as PST Timestamp?

查看文档: https://www.postgresql.org/docs/9.3/static/datatype-datetime.html

Table 8-9 显示 timestamp [ (p) ] with time zone 但方括号和普通括号让我失望,没有示例说明如何实现它。

例如如果我有以下内容,我将如何使 some_time 列包含 PST 时间戳而不是 UTC?

CREATE TABLE "mytable" (
  id SERIAL PRIMARY KEY,
  some_time TIMESTAMP
); 

您不能声明具有时区指定时间戳类型的列。 文档中的 p 表示 precision:

time, timestamp, and interval accept an optional precision value p

关于p的值:

For the time types, the allowed range of p is from 0 to 6 when eight-byte integer storage is used, or from 0 to 10 when floating-point storage is used.

我认为您想使用 timestamp without time zone 列,然后使用 AT TIME ZONE:

将它们转换为所需的时区
SELECT some_time AT TIME ZONE 'PST', some_time AT TIME ZONE 'UTC+2' FROM mytable;

fiddle