Skip to content

Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.

fix(schema): map SQL float columns to xsd:float/xsd:double, not xsd:decimal

FABIOTESS197086440cc0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d71b7f87..e3f15645 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,7 +4,25 @@ All notable changes to Open Ontologies are documented here.
## [Unreleased]
-_Nothing yet._
+### Fixed
+- **SQL floating-point columns were mapped to `xsd:decimal`.** `real`,
+ `float4`, `float`, `float8`, `double` and `double precision` all resolved to
+ `xsd:decimal` in `SchemaIntrospector::sql_to_xsd`, so every ontology
+ generated by `onto_import_schema` / `onto_sql_ingest` from a table with a
+ float column carried a wrong range. `xsd:decimal` is integers over powers of
+ ten: it cannot represent `NaN`, `INF` or `-INF`, and it asserts an exactness
+ IEEE 754 does not have. `real` and `float4` now map to `xsd:float`, and
+ `double`, `double precision` and `float8` to `xsd:double`.
+
+ Bare `float` is dialect-dependent (Postgres `float8`, DuckDB `float4`) and
+ maps to `xsd:double`, widening rather than narrowing: every `xsd:float`
+ value is exactly representable as an `xsd:double`, so the reverse choice
+ would declare a range narrower than the data. `numeric` and `decimal` are
+ unaffected and still map to `xsd:decimal`.
+
+ **This changes output.** Ontologies generated before this release state
+ `xsd:decimal` on float-backed properties; regenerate them, or expect
+ range mismatches against ones generated after. Reported in #76.
## 1.1.1 — 2026-08-03
diff --git a/src/schema.rs b/src/schema.rs
index 3dda57f3..a2d29dac 100644
--- a/src/schema.rs
+++ b/src/schema.rs
@@ -37,8 +37,21 @@ impl SchemaIntrospector {
"integer" | "int" | "bigint" | "smallint" | "tinyint" | "hugeint"
| "int4" | "int8" | "int2" | "int1" | "serial" | "bigserial"
| "smallserial" | "ubigint" | "uinteger" | "usmallint" | "utinyint" => "xsd:integer",
- "numeric" | "decimal" | "real" | "double precision" | "double"
- | "float" | "float4" | "float8" => "xsd:decimal",
+ "numeric" | "decimal" => "xsd:decimal",
+ // IEEE 754 binary floats are deliberately NOT xsd:decimal. That
+ // type's value space is integers over powers of ten, so it cannot
+ // represent NaN, INF or -INF, and asserting it claims an exactness
+ // the source column does not have.
+ "real" | "float4" => "xsd:float",
+ // Bare `float` is dialect-dependent: Postgres reads it as float8,
+ // DuckDB as float4 (an alias of REAL). Widen rather than narrow.
+ // Every xsd:float value is exactly representable as an xsd:double,
+ // so calling a DuckDB single a double overstates the range without
+ // misrepresenting any value; the reverse would declare a range
+ // narrower than the data. Parameterised `float(p)` normalises to
+ // this arm too, which is the same safe direction under Postgres,
+ // where p <= 24 would otherwise select real.
+ "double precision" | "double" | "float" | "float8" => "xsd:double",
"boolean" | "bool" => "xsd:boolean",
"date" => "xsd:date",
"timestamp" | "timestamptz" | "timestamp without time zone"
diff --git a/tests/schema_test.rs b/tests/schema_test.rs
index 2c319da3..918bf45a 100644
--- a/tests/schema_test.rs
+++ b/tests/schema_test.rs
@@ -63,6 +63,31 @@ fn test_sql_type_to_xsd() {
assert_eq!(SchemaIntrospector::sql_to_xsd("unknown_type"), "xsd:string");
}
+/// IEEE 754 columns must not map to xsd:decimal, whose value space excludes
+/// NaN and the infinities and implies an exactness binary floats do not have.
+#[test]
+fn test_sql_float_types_map_to_binary_xsd_types() {
+ // Exact decimal types keep xsd:decimal.
+ assert_eq!(SchemaIntrospector::sql_to_xsd("numeric"), "xsd:decimal");
+ assert_eq!(SchemaIntrospector::sql_to_xsd("decimal"), "xsd:decimal");
+ assert_eq!(SchemaIntrospector::sql_to_xsd("DECIMAL(18,2)"), "xsd:decimal");
+
+ // Single precision.
+ assert_eq!(SchemaIntrospector::sql_to_xsd("real"), "xsd:float");
+ assert_eq!(SchemaIntrospector::sql_to_xsd("float4"), "xsd:float");
+
+ // Double precision.
+ assert_eq!(SchemaIntrospector::sql_to_xsd("double precision"), "xsd:double");
+ assert_eq!(SchemaIntrospector::sql_to_xsd("double"), "xsd:double");
+ assert_eq!(SchemaIntrospector::sql_to_xsd("float8"), "xsd:double");
+
+ // Bare `float` is ambiguous across dialects (Postgres float8, DuckDB
+ // float4). It widens to xsd:double, including when parameterised.
+ assert_eq!(SchemaIntrospector::sql_to_xsd("float"), "xsd:double");
+ assert_eq!(SchemaIntrospector::sql_to_xsd("FLOAT(24)"), "xsd:double");
+ assert_eq!(SchemaIntrospector::sql_to_xsd("float(53)"), "xsd:double");
+}
+
#[test]
fn test_generate_turtle_not_null_cardinality() {
let tables = vec![TableInfo {