Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

NUMERIC read as DOUBLE doesn't match Postgres's float8 cast

Closed
#604 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

A pull request for this has already been merged.

  • #610 by @ItsM0rty — merged

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
70/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp, postgresql
Domain
databases

Research direction

The issue identifies DecimalConversionDouble in the binary numeric decoder; start by finding that implementation and the tests for decoding PostgreSQL numeric values as DOUBLE. Compare binary protocol results with the text protocol and PostgreSQL's numeric::float8 cast for the reported values. Done means the binary path returns the same nearest double as PostgreSQL for these cases.

Written by the indexing model from the issue text.

Description

On main (8d201d4), numeric values that the extension reads as DOUBLE (unconstrained numeric, or a numeric too wide for DuckDB's DECIMAL) sometimes differ from Postgres's own numeric::float8 cast:

memory D ATTACH '' as pg (TYPE postgres);
memory D SELECT n AS duckdb, f AS postgres, n = f AS same
         FROM postgres_query('pg', 'SELECT n, n::float8 AS f FROM (
            SELECT 8629433::numeric / 1000
            UNION ALL SELECT avg(x) FROM (VALUES (275.38), (232.58), (785.33)) v(x)
            UNION ALL SELECT 1e32
          ) t(n)');
┌───────────────────────┬───────────────────┬─────────┐
│        duckdb         │     postgres      │  same   │
│        double         │      double       │ boolean │
├───────────────────────┼───────────────────┼─────────┤
│     8629.432999999999 │          8629.433 │ false   │
│    431.09666666666664 │ 431.0966666666667 │ false   │
│ 9.999999999999999e+31 │             1e+32 │ false   │
└───────────────────────┴───────────────────┴─────────┘

These aren't the nearest double to the exact value, which is what Postgres's cast (through strtod) gives.

With SET pg_use_text_protocol = true the same query returns the correct values, so the problem is in decoding the binary numeric format. The cause is DecimalConversionDouble, which builds the double with floating-point arithmetic that rounds at each step.

Dominant language
C++
Stars
373
Forks
112
Avg merge
9h 48m
Merged PRs (30d)
28

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from duckdb/duckdb-postgres

All issues in duckdb/duckdb-postgres

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.