Skip to main content

ArithmeticOutput

Trait ArithmeticOutput 

Source
pub trait ArithmeticOutput<Rhs: Numeric = Self, Op = ArithmeticOp>: Numeric {
    type Output: Numeric;
    type Nullability: ArithmeticNullability;
}
Expand description

The SQL type produced by Self <op> Rhs, where both sides are Numeric.

The output follows each database’s promotion rules:

  • SQLite: Integer op Integer is Integer; any Real makes it Real; Numeric with Integer stays Numeric; Any with anything is Any.
  • PostgreSQL: integers widen to the wider integer (Int2 + Int8 is Int8); an integer with a float gives a float (Int4 + Float8 is Float8; only Int2 with Float4 stays Float4); Numeric with an integer stays Numeric; Numeric with a float gives Float8.
  • MySQL: integer +, - and * give BigInt (BigIntUnsigned if an operand is unsigned); integer % gives BigInt or BigIntUnsigned following the left operand; / of exact values gives Decimal; Decimal with an integer gives Decimal; any Float or Double operand gives Double. Year counts as an unsigned integer.

Op selects the operator (AddOp, SubOp, MulOp, DivOp, RemOp). The default, ArithmeticOp, is an operator-independent form implemented only for SQLite and PostgreSQL, whose result type does not depend on the operator.

§Examples

use drizzle_types::{ArithmeticOutput, Numeric};
use drizzle_types::postgres::types::{Float8, Int2, Int4, Int8};

fn output<L, R, O>()
where
    L: ArithmeticOutput<R, Output = O>,
    R: Numeric,
    O: Numeric,
{
}

output::<Int2, Int8, Int8>(); // smallint + bigint -> bigint
output::<Int4, Float8, Float8>(); // integer + double -> double

Required Associated Types§

Source

type Output: Numeric

The resulting SQL type of the arithmetic expression.

Source

type Nullability: ArithmeticNullability

Whether the operator itself can produce NULL even from non-NULL operands: / and % on SQLite’s Integer, Real and Numeric and on every MySQL numeric type, which return NULL for a zero divisor. PostgreSQL raises an error instead, so its operators only propagate operand nullability.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl ArithmeticOutput for Any

Source§

type Output = Any

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput for Float4

Source§

type Output = Float4

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput for Float8

Source§

type Output = Float8

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput for Int2

Source§

type Output = Int2

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput for Int4

Source§

type Output = Int4

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput for Int8

Source§

type Output = Int8

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput for Integer

Source§

type Output = Integer

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput for drizzle_types::sqlite::types::Numeric

Source§

type Output = Numeric

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput for drizzle_types::postgres::types::Numeric

Source§

type Output = Numeric

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput for Real

Source§

type Output = Real

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Any> for Integer

Source§

type Output = Any

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Any> for drizzle_types::sqlite::types::Numeric

Source§

type Output = Any

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Any> for Real

Source§

type Output = Any

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Float4> for Float8

Source§

type Output = Float8

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Float4> for Int2

Source§

type Output = Float4

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Float4> for Int4

Source§

type Output = Float8

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Float4> for Int8

Source§

type Output = Float8

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Float4> for drizzle_types::postgres::types::Numeric

Source§

type Output = Float8

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Float8> for Float4

Source§

type Output = Float8

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Float8> for Int2

Source§

type Output = Float8

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Float8> for Int4

Source§

type Output = Float8

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Float8> for Int8

Source§

type Output = Float8

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Float8> for drizzle_types::postgres::types::Numeric

Source§

type Output = Float8

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Int2> for Float4

Source§

type Output = Float4

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Int2> for Float8

Source§

type Output = Float8

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Int2> for Int4

Source§

type Output = Int4

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Int2> for Int8

Source§

type Output = Int8

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Int2> for drizzle_types::postgres::types::Numeric

Source§

type Output = Numeric

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Int4> for Float4

Source§

type Output = Float8

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Int4> for Float8

Source§

type Output = Float8

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Int4> for Int2

Source§

type Output = Int4

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Int4> for Int8

Source§

type Output = Int8

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Int4> for drizzle_types::postgres::types::Numeric

Source§

type Output = Numeric

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Int8> for Float4

Source§

type Output = Float8

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Int8> for Float8

Source§

type Output = Float8

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Int8> for Int2

Source§

type Output = Int8

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Int8> for Int4

Source§

type Output = Int8

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Int8> for drizzle_types::postgres::types::Numeric

Source§

type Output = Numeric

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Integer> for Any

Source§

type Output = Any

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Integer> for drizzle_types::sqlite::types::Numeric

Source§

type Output = Numeric

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Integer> for Real

Source§

type Output = Real

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Numeric> for Any

Source§

type Output = Any

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Numeric> for Float4

Source§

type Output = Float8

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Numeric> for Float8

Source§

type Output = Float8

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Numeric> for Int2

Source§

type Output = Numeric

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Numeric> for Int4

Source§

type Output = Numeric

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Numeric> for Int8

Source§

type Output = Numeric

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Numeric> for Integer

Source§

type Output = Numeric

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Numeric> for Real

Source§

type Output = Real

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Real> for Any

Source§

type Output = Any

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Real> for Integer

Source§

type Output = Real

Source§

type Nullability = PropagateNullability

Source§

impl ArithmeticOutput<Real> for drizzle_types::sqlite::types::Numeric

Source§

type Output = Real

Source§

type Nullability = PropagateNullability