MCPcopy Index your code
hub / github.com/sqlalchemy/sqlalchemy / Float

Class Float

lib/sqlalchemy/sql/sqltypes.py:672–776  ·  view source on GitHub ↗

Type representing floating point types, such as ``FLOAT`` or ``REAL``. This type returns Python ``float`` objects by default, unless the :paramref:`.Float.asdecimal` flag is set to ``True``, in which case they are coerced to ``decimal.Decimal`` objects. When a :paramref:`.Float.pre

Source from the content-addressed store, hash-verified

670
671
672class Float(NumericCommon[_N], TypeEngine[_N]):
673 """Type representing floating point types, such as ``FLOAT`` or ``REAL``.
674
675 This type returns Python ``float`` objects by default, unless the
676 :paramref:`.Float.asdecimal` flag is set to ``True``, in which case they
677 are coerced to ``decimal.Decimal`` objects.
678
679 When a :paramref:`.Float.precision` is not provided in a
680 :class:`_types.Float` type some backend may compile this type as
681 an 8 bytes / 64 bit float datatype. To use a 4 bytes / 32 bit float
682 datatype a precision <= 24 can usually be provided or the
683 :class:`_types.REAL` type can be used.
684 This is known to be the case in the PostgreSQL and MSSQL dialects
685 that render the type as ``FLOAT`` that&#x27;s in both an alias of
686 ``DOUBLE PRECISION``. Other third party dialects may have similar
687 behavior.
688 """
689
690 __visit_name__ = "float"
691
692 @overload
693 def __init__(
694 self: Float[float],
695 precision: Optional[int] = ...,
696 asdecimal: Literal[False] = ...,
697 decimal_return_scale: Optional[int] = ...,
698 ): ...
699
700 @overload
701 def __init__(
702 self: Float[decimal.Decimal],
703 precision: Optional[int] = ...,
704 asdecimal: Literal[True] = ...,
705 decimal_return_scale: Optional[int] = ...,
706 ): ...
707
708 def __init__(
709 self: Float[_N],
710 precision: Optional[int] = None,
711 asdecimal: bool = False,
712 decimal_return_scale: Optional[int] = None,
713 ):
714 r"""
715 Construct a Float.
716
717 :param precision: the numeric precision for use in DDL ``CREATE
718 TABLE``. Backends **should** attempt to ensure this precision
719 indicates a number of digits for the generic
720 :class:`_sqltypes.Float` datatype.
721
722 .. note:: For the Oracle Database backend, the
723 :paramref:`_sqltypes.Float.precision` parameter is not accepted
724 when rendering DDL, as Oracle Database does not support float precision
725 specified as a number of decimal places. Instead, use the
726 Oracle Database-specific :class:`_oracle.FLOAT` datatype and specify the
727 :paramref:`_oracle.FLOAT.binary_precision` parameter. This is new
728 in version 2.0 of SQLAlchemy.
729

Calls

no outgoing calls