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