Postgres loses one digit when saves DateTimeOffset from .Net app (Dapper)

30 Views Asked by At

I create object:

{
 id = 123,
 dateTimeOffset = DateTime.UtcNow // 2024-02-27 21:42:43.7125911 +0h
}

and save it to postgres db with dapper. Then I read that object from db with dapper and get

2024-02-27 21:42:43.712591 +0h

As you could see, value from db is 1 digit shorter than original value.

Why does it happen? And how to fix it. Thank you.

1

There are 1 best solutions below

0
Islingre On

The resolution of PostgreSQL's timestamp and time types is 1 microsecond, as written here in the documentation: https://www.postgresql.org/docs/current/datatype-datetime.html

Your last digit corresponds to a tenth of a microsecond and therefore gets truncated.