Home > Mobile >  How to convert BIGINT to TIMESTAMPZ in a query?
How to convert BIGINT to TIMESTAMPZ in a query?

Time:02-15

Using:

  • PostgreSQL 14 in Supabase
  • Grafana cloud

I am trying to convert BIGINT timestamp in milliseconds to TIMESTAMPZ in PostgreSQL 14.

The BIGINT is a constant stored in a $__to and $__from. I am trying to query data in a certain time range with this query:

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')

The query above result in this error:

function to_timestamp(bigint, unknown) does not exist

I have looked into these topics but couldn't find a solution that would work:

  1. enter image description here

    Type of my timestampz column:

    enter image description here

    CodePudding user response:

    You have to use the single-argument form of to_timestamp:

    SELECT to_timestamp(1644853209.6);
    
           to_timestamp       
    ══════════════════════════
     2022-02-14 16:40:09.6 01
    (1 row)
    
  • Related