Skip to content

JSON path ':float' is single precision on MySQL and double precision on PostgreSQL #1704

In review

Description

@dimitri-yatsenko

Summary

The :type suffix of a JSON path is passed through to each backend as is. The same DataJoint expression therefore evaluates differently on the two backends:

  • On MySQL, :float becomes json_value(… returning float), which is single precision.
  • On PostgreSQL, it becomes (jsonb_extract_path_text(…))::float, which is double precision (float = float8 in PostgreSQL).

A restriction or computed attribute that uses :float can return different rows on the two backends.

Reproduction

Any table with a json attribute shows it, for example doc : json holding {"a": 0.1}:

T.proj(a="doc.a:float") & "a = 0.1"

The SQL each backend runs, evaluated directly on MySQL 8.0.46 and PostgreSQL 17.12:

Expression MySQL 8.0.46 PostgreSQL 17.12
value of doc.a:float for 0.1234567891234 0.123457 0.1234567891234
doc.a:float = 0.1 for {"a": 0.1} false true
doc.a:double = 0.1 for {"a": 0.1} true true

So (T.proj(a="doc.a:float") & "a = 0.1") returns the row on PostgreSQL and drops it on MySQL. Aggregates such as avg() over :float values also differ in the 7th significant digit.

Where

  • adapters/mysql.py, json_path_expr: appends returning {return_type} unchanged.
  • adapters/postgres.py, json_path_expr: maps only signed/unsigned → integer and double → double precision; everything else, including float, is cast as is.

Possible fix

Make the suffix mean the same thing on both backends. Either:

  • map float to double on MySQL, so :float is double precision everywhere (PostgreSQL's meaning, and what Python's float is); or
  • accept DataJoint core type names in the suffix (float32, float64, int32, …) and translate them per backend, and document that.

Integer suffixes have a similar gap: on MySQL 8.0.46, json_value(… returning int) is a syntax error (signed/unsigned work), while PostgreSQL accepts ::int. The core-type option would cover both.

Found while preparing the MySQL/PostgreSQL benchmark (datajoint/datajoint-docs#315), which uses :double and :signed to avoid it.

Activity

  1. added
    bug
    on Nov 20, 2026
  2. modified the milestones: v2.3.7, v2.4 on Nov 23, 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

    bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions