QuestDB Timestamp in Node.js

When I execute the following query in the QuestDB panel (localhost:9000), it returns the correct timestamp: 2024-01-01T00:00:00.000000Z (UTC, as recorded).

SELECT
    timestamp,
    first(open) AS open,
    max(high) AS high,
    min(low) AS low,
    last(close) AS close,
    sum(volume) AS volume,
    sum(quote_volume) AS quote_volume,
    sum(taker_buy_volume) AS taker_buy_volume,
    sum(taker_buy_quote_volume) AS taker_buy_quote_volume
FROM klines
WHERE symbol = 'BTCUSDT'
SAMPLE BY 1m
ORDER BY timestamp LIMIT 1;

However, when running the same query in Node.js using pg.query, the timestamp returned is 2023-12-31T19:00:00.000Z, meaning it incorrectly applies another UTC conversion.

How can I fix this?

as an option you can use:
cast(timestamp AS LONG) AS timestamp

Unfortunately, some PG Wire clients will convert the timestamp to local time. You can cast the timestamp to long, giving you epoch micros, and then convert them back client-side.

There is a related issue I can dig up in a little while.

1 Like

It seems in nodejs you can setup the TZ and the pg driver should honour it Data Types – node-postgres