Skip to main content

LogicalType

Enum LogicalType 

Source
#[non_exhaustive]
pub enum LogicalType {
Show 33 variants Null, Boolean, TinyInt, SmallInt, Integer, BigInt, HugeInt, UTinyInt, USmallInt, UInteger, UBigInt, UHugeInt, Float, Double, Decimal { width: u8, scale: u8, }, Varchar, Blob, Bit, Uuid, Date, Time, TimeTz, Timestamp, TimestampS, TimestampMs, TimestampNs, TimestampTz, Interval, List(Box<LogicalType>), Array(Box<LogicalType>, u32), Struct(Vec<Field>), Map(Box<LogicalType>, Box<LogicalType>), Union(Vec<Field>),
}
Expand description

What SQL thinks a value is.

Nulls are not in here. spec/10-sql-and-types.md says null is a per-value property at every nesting level, which makes it a property of a vector’s validity mask rather than of a type. The one exception is LogicalType::Null, which is the type of a literal NULL before anything has told it what it is, and which every other type absorbs during resolution.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Null

The type of an untyped NULL literal.

§

Boolean

BOOLEAN.

§

TinyInt

TINYINT, 8 bits signed.

§

SmallInt

SMALLINT, 16 bits signed.

§

Integer

INTEGER, 32 bits signed.

§

BigInt

BIGINT, 64 bits signed.

§

HugeInt

HUGEINT, 128 bits signed.

§

UTinyInt

UTINYINT, 8 bits unsigned.

§

USmallInt

USMALLINT, 16 bits unsigned.

§

UInteger

UINTEGER, 32 bits unsigned.

§

UBigInt

UBIGINT, 64 bits unsigned.

§

UHugeInt

UHUGEINT, 128 bits unsigned.

§

Float

FLOAT, IEEE 754 binary32.

§

Double

DOUBLE, IEEE 754 binary64.

§

Decimal

DECIMAL(width, scale), stored in the narrowest integer that holds width digits.

Fields

§width: u8

Total number of decimal digits, 1 through 38.

§scale: u8

Digits to the right of the point, no greater than width.

§

Varchar

VARCHAR. Length modifiers parse and are then ignored, as they are in DuckDB.

§

Blob

BLOB.

§

Bit

BIT, a bit string.

§

Uuid

UUID.

§

Date

DATE, days since 1970-01-01.

§

Time

TIME, microseconds since midnight.

§

TimeTz

TIME WITH TIME ZONE.

§

Timestamp

TIMESTAMP, microseconds since the epoch.

§

TimestampS

TIMESTAMP_S, seconds since the epoch.

§

TimestampMs

TIMESTAMP_MS, milliseconds since the epoch.

§

TimestampNs

TIMESTAMP_NS, nanoseconds since the epoch.

§

TimestampTz

TIMESTAMP WITH TIME ZONE.

§

Interval

INTERVAL, the months, days and microseconds triple.

§

List(Box<LogicalType>)

T[], a variable length list.

§

Array(Box<LogicalType>, u32)

T[n], a fixed length array.

§

Struct(Vec<Field>)

STRUCT(name type, ...).

§

Map(Box<LogicalType>, Box<LogicalType>)

MAP(key, value).

§

Union(Vec<Field>)

UNION(tag type, ...).

Implementations§

Source§

impl LogicalType

Source

pub fn decimal(width: u8, scale: u8) -> Result<Self>

A DECIMAL(width, scale), checked.

§Errors

If the width is zero or above 38, or the scale is greater than the width. Those are the same bounds DuckDB enforces and the message is the same message.

Source

pub fn list(element: Self) -> Self

A list of element.

Source

pub fn array(element: Self, length: u32) -> Self

A fixed length array of element.

Source

pub fn map(key: Self, value: Self) -> Self

A map from key to value.

Source

pub fn physical(&self) -> PhysicalType

How this type is laid out.

Source

pub fn is_numeric(&self) -> bool

Whether arithmetic applies.

Source

pub fn is_integer(&self) -> bool

Whether this is one of the integer types, signed or unsigned.

Source

pub fn is_temporal(&self) -> bool

Whether this is a date, a time, a timestamp or an interval.

Source

pub fn is_nested(&self) -> bool

Whether this type contains other types.

Nested types are stored columnar all the way down, so this is the question of whether a column of this type is one column chunk or several.

Source

pub fn promote(&self, other: &Self) -> Option<Self>

The type both of these can be cast to without losing a value, if there is one.

This is DuckDB’s MaxLogicalType and it is what decides the type of a + b, of the arms of a CASE, and of the columns of a UNION. The rule is a total order over the numeric types with everything else absorbing into VARCHAR only when it is asked to, and NULL absorbing into anything, which is what makes CASE WHEN c THEN NULL ELSE 1 END an integer.

Mixing signed and unsigned widens rather than reinterprets, so INTEGER and UINTEGER promote to BIGINT and not to either of themselves. That costs a byte per value on a case that is rare and it is the only version that never silently changes a number, which matters more here than the byte does: a wrong answer that is off by 4,294,967,296 is the worst kind of bug this engine can have.

Returns None when there is no such type, which is the binder’s cue to raise rather than to guess. Two different structs are None and not a struct of promoted fields, because field order and field names would have to match and a rule that sometimes works is worse here than one that never does.

Source

pub fn children(&self) -> Vec<Self>

The types this one contains, in child column order, or empty for a scalar type.

Source

pub fn parse(text: &str) -> Result<Self>

Parses a SQL type name, aliases included.

§Errors

If the text is not a type name this understands. The message names the offending word, because a type parse failure two levels inside a STRUCT is otherwise unreadable.

Trait Implementations§

Source§

impl Clone for LogicalType

Source§

fn clone(&self) -> LogicalType

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LogicalType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for LogicalType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for LogicalType

Source§

impl Hash for LogicalType

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for LogicalType

Source§

fn eq(&self, other: &LogicalType) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for LogicalType

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.