如何在查询中将 BIGINT 转换为 TIMESTAMP?

How to convert BIGINT to TIMESTAMPZ in a query?

使用:

我正在尝试将 BIGINT 时间戳以毫秒为单位转换为 PostgreSQL 14 中的 TIMESTAMPZ

BIGINT是一个常量,存储在$__to$__from中。我正在尝试使用此查询查询特定时间范围内的数据:

SELECT
  "timestamp" AS "time",
  etalon,
  humidity,
  temperature
FROM "values"
WHERE
  timestamp >= TO_TIMESTAMP($__from, 'DD/MM/YYYY HH24:MI:SS')
  and timestamp <  TO_TIMESTAMP($__to, 'DD/MM/YYYY HH24:MI:SS')

以上查询导致此错误:

function to_timestamp(bigint, unknown) does not exist

我研究了这些主题,但找不到可行的解决方案:

  1. Postgres timestamp to unix time in milliseconds as a bigint
  2. https://dba.stackexchange.com/questions/215354/convert-date-format-into-bigint-format-in-postgresql
  3. How to format bigint field into a date in Postgresql?

编辑

使用Quassnoi解决方案也不起作用:

SELECT
  "timestamp" AS "time",
  etalon,
  humidity,
  temperature
FROM "values"
WHERE
  timestamp >= TO_CHAR(TO_TIMESTAMP(1644770125499 / 1000), 'DD/MM/YYYY HH24:MI:SS')
  and timestamp <  TO_CHAR(TO_TIMESTAMP(1644770125499 / 1000), 'DD/MM/YYYY HH24:MI:SS')

结果:

operator does not exist: timestamp with time zone >= text

根据评论中的建议,我确实转换了 BIGINT,但时间戳看起来很奇怪:

我的 timestampz 列的类型:

您必须使用 single-argument 形式的 to_timestamp:

SELECT to_timestamp(1644853209.6);

       to_timestamp       
══════════════════════════
 2022-02-14 16:40:09.6+01
(1 row)