Skip to content

Commit de288ab

Browse files
committed
Types: Improve support for FLOAT type, converging to FLOAT or DOUBLE
1 parent 7b12867 commit de288ab

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/sqlalchemy_cratedb/compiler.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,27 @@ def visit_TIMESTAMP(self, type_, **kw):
257257
def visit_BLOB(self, type_, **kw):
258258
return "STRING"
259259

260+
def visit_FLOAT(self, type_, **kw):
261+
"""
262+
From `sqlalchemy.sql.sqltypes.Float`.
263+
264+
When a :paramref:`.Float.precision` is not provided in a
265+
:class:`_types.Float` type some backend may compile this type as
266+
an 8 bytes / 64 bit float datatype. To use a 4 bytes / 32 bit float
267+
datatype a precision <= 24 can usually be provided or the
268+
:class:`_types.REAL` type can be used.
269+
This is known to be the case in the PostgreSQL and MSSQL dialects
270+
that render the type as ``FLOAT`` that's in both an alias of
271+
``DOUBLE PRECISION``. Other third party dialects may have similar
272+
behavior.
273+
"""
274+
if not type_.precision:
275+
return "FLOAT"
276+
elif type_.precision <= 24:
277+
return "FLOAT"
278+
else:
279+
return "DOUBLE"
280+
260281

261282
class CrateCompiler(compiler.SQLCompiler):
262283
def visit_getitem_binary(self, binary, operator, **kw):

0 commit comments

Comments
 (0)