Skip to content

πŸ› Bug Report: Postgres adapter truncates float columns to 14 digitsΒ #14220

Closed

Description

@JoshiJoshiJoshi

πŸ‘Ÿ Reproduction steps

  1. Table with a float column f (Postgres adapter).
  2. POST …/rows with {"data": {"f": 1234567.123456789}}.
  3. Read the row (or SELECT f FROM … in Postgres).

πŸ‘ Expected behavior

f = 1234567.123456789 – a double precision column holds 15–17 significant digits.

πŸ‘Ž Actual Behavior

f = 1234567.1234568, both in the API response and in the stored column. Every float is cut to 14 significant digits on write:

Written Stored / returned
0.30000000000000004 0.3
1/3 0.33333333333333
2.718281828459045 2.718281828459
52.52000812345678 52.520008123457
123456789012345 123456789012340
9007199254740992 9007199254741000
99999999999999.98 100000000000000
1.7976931348623157e308 1.7976931348623e+308
point [13.404954123456789, 52.520008123456789] [13.404954123457, 52.520008123457]

The same happens with updateRow, createRows, upsertRows, transactions, and after any later update of another column of the row (the whole row is re-written). A value computed in SQL by an operator (divide 3) is also truncated as soon as the row is written again. Float arrays keep full precision (they are stored as JSON). Two runs, identical results.

Cause: the Postgres adapter binds double values with PDO::PARAM_STR (Adapter/Postgres.php L1978–L1986, used e.g. in createDocument() L1036–L1046), so PHP converts the float to a string using the precision ini setting, which is 14 in the Appwrite image (php -r 'echo ini_get("precision");' β†’ 14). There is a helper getFloatPrecision() (%.17F, SQL.php L43–L46), but the write paths do not use it. Query filter values are rounded the same way (equal 1234567.123456789 matches the stored 1234567.1234568, greaterThan 1234567.12345678 does not match it), so equality filters keep working, but range filters near the cut-off do not behave as written. utopia-php/database main still binds doubles this way.

Consequences: integers above ~10^14 kept in float columns change (123456789012345 β†’ 123456789012340), values that clients compare exactly (e.g. after a round trip through another system) no longer match. For typical coordinates or money amounts the loss is below the 12th decimal and harmless.

🎲 Appwrite version

2.3.0 (utopia-php/database 7.3.11)

πŸ’» Operating system

Linux (Debian 12), Docker

🧱 Your Environment

Self-hosted Appwrite 2.3.0, Postgres adapter (PostgreSQL 18).

πŸ’‘ Suggested fix

Bind floats with a round-trip-safe representation on all write paths (e.g. getFloatPrecision() / var_export-style with serialize_precision = -1), or set precision = 17 (or -1) in the Appwrite PHP image.

πŸ‘€ Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find a similar issue

🏒 Have you read the Code of Conduct?

  • I have read the Code of Conduct

Activity

  1. added
    product / databases
    product / storage
    sdk / cli
    on Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    product / databasesproduct / storagesdk / cli

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions