Re: Reading timestamp values from Datums gives garbage values

Поиск
Список
Период
Сортировка
От Aleksander Alekseev
Тема Re: Reading timestamp values from Datums gives garbage values
Дата
Msg-id CAJ7c6TOtm0q4f_jMTjR+KoFrb-GJ=r0VJzUw2YKz89oSRSP=FA@mail.gmail.com
обсуждение исходный текст
Ответ на Reading timestamp values from Datums gives garbage values  (Sushrut Shivaswamy <sushrut.shivaswamy@gmail.com>)
Ответы Re: Reading timestamp values from Datums gives garbage values
Список pgsql-hackers
Hi,

> 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.
> ```
>
> Datum current_timestamp = SPI_getbinval(SPI_tuptable->vals[i], SPI_tuptable->tupdesc, 5, &isnull);
>
> double current_time = DatumGetFloat8(current_timestamp); // prints 0
>
> int64 time = DatumGetUint64(current_timestamp); // prints 5293917674
>
> ```
>
> Can you help me out with the correct way to read EPOCH values from datums?

I don't entirely understand why you are using DatumGetFloat8() /
DatumGetUint64() and double / int64 types. There are
DatumGetTimestamp() / DatumGetTimestampTz() and Timestamp /
TimestampTz.

I recommend using the PostgreSQL code as a source of more examples of
how to deal with the given types. The file pg_proc.dat is a good entry
point. See also commit 260a1f18 [1] and PostgreSQL documentation [2].

[1]: https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=260a1f18
[2]: https://www.postgresql.org/docs/16/xfunc-c.html

-- 
Best regards,
Aleksander Alekseev



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Dave Page
Дата:
Сообщение: Re: zlib detection in Meson on Windows broken?
Следующее
От: John Naylor
Дата:
Сообщение: Re: PostgreSQL 17 Beta 1 release announcement draft