Re: Reading timestamp values from Datums gives garbage values - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Reading timestamp values from Datums gives garbage values
Date
Msg-id 3528491.1716223454@sss.pgh.pa.us
Whole thread Raw
In response to Re: Reading timestamp values from Datums gives garbage values  (Tomas Vondra <tomas.vondra@enterprisedb.com>)
List pgsql-hackers
Tomas Vondra <tomas.vondra@enterprisedb.com> writes:
> On 5/20/24 16:37, Sushrut Shivaswamy wrote:
>> When trying to read the query response from the Datum, I get garbage values.
>> I've tried various types and none of them read the correct value.

> TimestampTz is int64, so using DatumGetInt64 is probably the simplest
> solution. And it's the number of microseconds, so X/1e6 should give you
> the epoch.

Don't forget that TimestampTz uses an epoch (time zero) of 2000-01-01.
If you want a Unix-convention value where the epoch is 1970-01-01,
you'll need to add 30 years to the result.

The reported values seem pretty substantially off, though ---
5293917674 would be barely an hour and a half later than the
epoch, which seems unlikely to be the value Sushrut intended
to test with.  I suspect a mistake that's outside the fragment
of code we were shown.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Chapman Flack
Date:
Subject: Re: Reading timestamp values from Datums gives garbage values
Next
From: "Jonathan S. Katz"
Date:
Subject: Re: PostgreSQL 17 Beta 1 release announcement draft