You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Consider an opt-in behavior to truncate high-precision PG numeric types to read them as decimal #6125
Over the years, we've received many reports of people trying to read numeric/decimal values from PostgreSQL which have too much precision for .NET decimal (see #448). There are several workarounds for specific use-cases:
BigInteger can be used for integer-only values.
Values can be fetched as text for display purposes.
Data can be truncated in the database to remove the extra precision which causes reading to fail.
However, in some cases the above are insufficient, and we've received requests to allow these values to be truncated as part of the reading process. This would be an explicit opt-in, as Npgsql does not truncate or lose information by default; but it could make sense for some use-cases.
Reacted by Maksim Strebkov, pantonis, johnfedak, David Boone, seth, Matthew Monahan and Juan Diego Herrera
There are 2 types of overflow here which might need to be handled separately. There is simply exceeding the range of allowed .Net values (i.e. numerics < Decimal.MinValue or > Decimal.MaxValue)
This is not our primary concern.
The scenario we are hitting is the precision of the PostgreSQL numeric is exceeding the precision allowed by System.Decimal. And in this case we would simply like the PostgreSQL value rounded/truncated to the precision allowed by .Net
The full precision of the source numeric in our cases is almost always generated by floating point division and is immaterial to the application
Yes, this issue is indeed about precision, not range - I don't think we'd ever truncate e.g. a numeric that's beyond Decimal.MaxValue to Decimal.MaxValue, since that would return completely different data. I'll update the issue title to make that clear.
Beyond that, note that you should already be able to perform the truncate database-side, in SQL.
changed the title [-]Consider an opt-in behavior to truncate out-of-range PG numeric types to read them as decimal[/-][+]Consider an opt-in behavior to truncate high-precision PG numeric types to read them as decimal[/+]on Jul 19, 2025
Activity
johnfedak commentedon Jul 18, 2025
There are 2 types of overflow here which might need to be handled separately. There is simply exceeding the range of allowed .Net values (i.e. numerics < Decimal.MinValue or > Decimal.MaxValue)
This is not our primary concern.
The scenario we are hitting is the precision of the PostgreSQL numeric is exceeding the precision allowed by System.Decimal. And in this case we would simply like the PostgreSQL value rounded/truncated to the precision allowed by .Net
The full precision of the source numeric in our cases is almost always generated by floating point division and is immaterial to the application
roji commentedon Jul 19, 2025
Yes, this issue is indeed about precision, not range - I don't think we'd ever truncate e.g. a numeric that's beyond Decimal.MaxValue to Decimal.MaxValue, since that would return completely different data. I'll update the issue title to make that clear.
Beyond that, note that you should already be able to perform the truncate database-side, in SQL.
[-]Consider an opt-in behavior to truncate out-of-range PG numeric types to read them as decimal[/-][+]Consider an opt-in behavior to truncate high-precision PG numeric types to read them as decimal[/+]klinki commentedon Feb 21, 2026
I can't wait for this one to be implemented, this is causing me a lot of trouble.
I'm in the process of migration from MySQL to PostgreSQL and now I'm fighting with that.