Skip to content

[ES-1877316] Promote Float(precision>24) to DOUBLE in CREATE TABLE#65

Open
jayantsing-db wants to merge 1 commit into
mainfrom
jayant-singh_data/fix-float64-precision-loss
Open

[ES-1877316] Promote Float(precision>24) to DOUBLE in CREATE TABLE#65
jayantsing-db wants to merge 1 commit into
mainfrom
jayant-singh_data/fix-float64-precision-loss

Conversation

@jayantsing-db
Copy link
Copy Markdown

@jayantsing-db jayantsing-db commented May 25, 2026

SQLAlchemy's default visit_float drops the precision argument when rendering for Databricks (no FLOAT(p) form exists), so Float(precision=53) silently compiled to a 32-bit FLOAT column. pandas.DataFrame.to_sql maps float64 to Float(precision=53), so every to_sql round-trip of a float64 column was being permanently truncated at the CREATE TABLE step — no way to recover the lost bits later, even after the INSERT-side fix in databricks-sql-python v4.2.6.

Add a @compiles(Float, "databricks") that promotes to DOUBLE when precision > 24, matching the SQL-standard cutover from single to double precision. Float() without precision keeps the current FLOAT behavior; sqlalchemy.types.FLOAT (uppercase, explicit 32-bit) and sqlalchemy.types.Double are unaffected because they have their own visit_name.

Co-authored-by: Isaac

SQLAlchemy's default visit_float drops the precision argument when
rendering for Databricks (no FLOAT(p) form exists), so Float(precision=53)
silently compiled to a 32-bit FLOAT column. pandas.DataFrame.to_sql maps
float64 to Float(precision=53), so every to_sql round-trip of a float64
column was being permanently truncated at the CREATE TABLE step — no way
to recover the lost bits later, even after the INSERT-side fix in
databricks-sql-python v4.2.6.

Add a @compiles(Float, "databricks") that promotes to DOUBLE when
precision > 24, matching the SQL-standard cutover from single to double
precision. Float() without precision keeps the current FLOAT behavior;
sqlalchemy.types.FLOAT (uppercase, explicit 32-bit) and sqlalchemy.types.Double
are unaffected because they have their own __visit_name__.

Co-authored-by: Isaac
Signed-off-by: Jayant Singh <jayant.singh@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant