MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / Numeric

Class Numeric

lib/sqlalchemy/sql/sqltypes.py:538–669  ·  view source on GitHub ↗

Base for non-integer numeric types, such as ``NUMERIC``, ``FLOAT``, ``DECIMAL``, and other variants. The :class:`.Numeric` datatype when used directly will render DDL corresponding to precision numerics if available, such as ``NUMERIC(precision, scale)``. The :class:`.Float` subcla

Source from the content-addressed store, hash-verified

536
537
538class Numeric(NumericCommon[_N], TypeEngine[_N]):
539 """Base for non-integer numeric types, such as
540 ``NUMERIC``, ``FLOAT``, ``DECIMAL``, and other variants.
541
542 The :class:`.Numeric` datatype when used directly will render DDL
543 corresponding to precision numerics if available, such as
544 ``NUMERIC(precision, scale)``. The :class:`.Float` subclass will
545 attempt to render a floating-point datatype such as ``FLOAT(precision)``.
546
547 :class:`.Numeric` returns Python ``decimal.Decimal`` objects by default,
548 based on the default value of ``True`` for the
549 :paramref:`.Numeric.asdecimal` parameter. If this parameter is set to
550 False, returned values are coerced to Python ``float`` objects.
551
552 The :class:`.Float` subtype, being more specific to floating point,
553 defaults the :paramref:`.Float.asdecimal` flag to False so that the
554 default Python datatype is ``float``.
555
556 .. note::
557
558 When using a :class:`.Numeric` datatype against a database type that
559 returns Python floating point values to the driver, the accuracy of the
560 decimal conversion indicated by :paramref:`.Numeric.asdecimal` may be
561 limited. The behavior of specific numeric/floating point datatypes
562 is a product of the SQL datatype in use, the Python :term:`DBAPI`
563 in use, as well as strategies that may be present within
564 the SQLAlchemy dialect in use. Users requiring specific precision/
565 scale are encouraged to experiment with the available datatypes
566 in order to determine the best results.
567
568 """
569
570 __visit_name__ = "numeric"
571
572 @overload
573 def __init__(
574 self: Numeric[decimal.Decimal],
575 precision: Optional[int] = ...,
576 scale: Optional[int] = ...,
577 decimal_return_scale: Optional[int] = ...,
578 asdecimal: Literal[True] = ...,
579 ): ...
580
581 @overload
582 def __init__(
583 self: Numeric[float],
584 precision: Optional[int] = ...,
585 scale: Optional[int] = ...,
586 decimal_return_scale: Optional[int] = ...,
587 asdecimal: Literal[False] = ...,
588 ): ...
589
590 def __init__(
591 self,
592 precision: Optional[int] = None,
593 scale: Optional[int] = None,
594 decimal_return_scale: Optional[int] = None,
595 asdecimal: bool = True,

Calls

no outgoing calls