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
JSON path ':float' is single precision on MySQL and double precision on PostgreSQL #1704
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.
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