userver: uPg timestamp support
Loading...
Searching...
No Matches
uPg timestamp support

The driver provides mapping from C++ std::chrono::time_point template type to Postgres timestamp (without time zone) data type.

To read/write timestamp with time zone Postgres data type a TimePointTz helper type is provided.

Postgres internal timestamp resolution is microseconds.

Note on time zones: std::chrono::time_point is an absolute time and does not correspond to any specific time zone. std::chrono::system_clock::now() and utils::Stringtime() return this kind of time point. It is always sent to PG as such, and you can think of it as an UTC time.

Postgres allows implicit conversion between TIMESTAMP and TIMESTAMP WITH TIME ZONE and it does not apply any offsets when doing so.

Because of this you MUST ensure that you always use the correct type:

namespace pg = storages::postgres;
pg::Transaction trx = ...;
auto now = std::chrono::system_clock::now();
// Send as timestamp without time zone
auto res = trx.Execute("select $1", now);
// Send as timestamp with time zone
res = trx.Execute("select $1", pg::TimePointTz{now});
// Read as timestamp
res[0].To(now);