如何将 time_t 插入 PostgreSQL 时间戳字段

rim*_*mas 2 c c++ postgresql timestamp

如何将 time_t 结构中收到的时间/日期插入到“没有时区的时间戳”类型的列中?

以前我使用 int8 作为数据类型,并且 time_t 非常适合,但我想知道如何使用 PQexecParams 调用来使用时间戳字段(最好不要将 time_t 从调用程序转换为字符串)。

Dan*_*ité 5

使用to_timestamp函数。例子:

 select to_timestamp(1000000000)::timestamp;
Run Code Online (Sandbox Code Playgroud)

结果:

   to_timestamp     
--------------------  
 2001-09-09 03:46:40
1行)