#[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
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
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
impl LogicalType
Sourcepub fn decimal(width: u8, scale: u8) -> Result<Self>
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.
Sourcepub fn physical(&self) -> PhysicalType
pub fn physical(&self) -> PhysicalType
How this type is laid out.
Sourcepub fn is_numeric(&self) -> bool
pub fn is_numeric(&self) -> bool
Whether arithmetic applies.
Sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Whether this is one of the integer types, signed or unsigned.
Sourcepub fn is_temporal(&self) -> bool
pub fn is_temporal(&self) -> bool
Whether this is a date, a time, a timestamp or an interval.
Sourcepub fn is_nested(&self) -> bool
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.
Sourcepub fn promote(&self, other: &Self) -> Option<Self>
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.
Trait Implementations§
Source§impl Clone for LogicalType
impl Clone for LogicalType
Source§fn clone(&self) -> LogicalType
fn clone(&self) -> LogicalType
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more