Skip to main content

DataTypeRef

Enum DataTypeRef 

Source
pub enum DataTypeRef {
Show 32 variants Int, BigInt, SmallInt, TinyInt, Float, Double, Real, Decimal { precision: u8, scale: u8, }, Numeric { precision: u8, scale: u8, }, Varchar { length: Option<u16>, }, Char { length: u16, }, Text, NVarchar { length: Option<u16>, }, NChar { length: u16, }, Binary { length: Option<u16>, }, VarBinary { length: Option<u16>, }, Blob, Date, Time { precision: Option<u8>, }, DateTime, DateTime2 { precision: Option<u8>, }, Timestamp { precision: Option<u8>, }, TimestampTz { precision: Option<u8>, }, Interval, Boolean, Bit, Json, Jsonb, Variant, Uuid, Xml, Custom(String),
}
Expand description

Simplified data type reference used in CAST / TRY_CAST / CONVERT expressions.

Unlike DataType, which captures full type metadata for DDL generation, DataTypeRef represents the type names commonly used in SQL expressions.

§Purpose

DataTypeRef is a lightweight, platform-agnostic type reference suitable for embedding in SQL expressions such as:

SELECT CAST(column_name AS VARCHAR(100)) FROM table
SELECT TRY_CAST(value AS DECIMAL(19, 4)) FROM source
SELECT CONVERT(DATETIME2, timestamp_col) FROM events

§Differences from DataType

AspectDataTypeDataTypeRef
Use caseDDL generationCAST / CONVERT expressions
MetadataFull (encoding, precision, storage format)Minimal (precision, scale, length)
Platform variantsUnified (one variant per type)Separate (Decimal vs Numeric, DateTime vs DateTime2)
CollectionsArray, Map, StructNot supported

§Platform-Specific Variants

Some types have separate variants for platform-specific naming:

  • Decimal vs Numeric — equivalent in SQL, but some dialects prefer one over the other
  • DateTime vs DateTime2 — SQL Server uses DATETIME2 for precision
  • Json vs Jsonb — PostgreSQL distinguishes between text and binary JSON
  • Boolean vs Bit — SQL Server uses BIT for boolean

§Example

use razeri_plugin_contract::DataTypeRef;

let varchar = DataTypeRef::Varchar { length: Some(100) };
let decimal = DataTypeRef::Decimal { precision: 19, scale: 4 };
let timestamp = DataTypeRef::Timestamp { precision: Some(6) };

Variants§

§

Int

4-byte signed integer (INT / INTEGER).

§

BigInt

8-byte signed integer (BIGINT).

§

SmallInt

2-byte signed integer (SMALLINT).

§

TinyInt

1-byte signed integer (TINYINT / SMALLINT in PostgreSQL).

§

Float

Single-precision float (REAL / FLOAT4).

§

Double

Double-precision float (DOUBLE PRECISION / DOUBLE).

§

Real

Single-precision float (REAL / FLOAT4).

§

Decimal

Exact numeric with precision and scale (DECIMAL(p, s)).

Fields

§precision: u8

Total number of digits.

§scale: u8

Number of digits after the decimal point.

§

Numeric

Exact numeric with precision and scale (NUMERIC(p, s)).

Equivalent to Decimal in SQL, but some dialects prefer NUMERIC over DECIMAL for exact numeric types.

Fields

§precision: u8

Total number of digits.

§scale: u8

Number of digits after the decimal point.

§

Varchar

Variable-length character string (VARCHAR(n)).

Fields

§length: Option<u16>

Maximum length in characters (None = unlimited/MAX).

§

Char

Fixed-length character string (CHAR(n)).

Fields

§length: u16

Length in characters.

§

Text

Unbounded text type (TEXT).

§

NVarchar

Variable-length Unicode string (NVARCHAR(n) — SQL Server).

Fields

§length: Option<u16>

Maximum length in characters (None = unlimited/MAX).

§

NChar

Fixed-length Unicode string (NCHAR(n) — SQL Server).

Fields

§length: u16

Length in characters.

§

Binary

Fixed-length binary data (BINARY(n)).

Fields

§length: Option<u16>

Length in bytes.

§

VarBinary

Variable-length binary data (VARBINARY(n)).

Fields

§length: Option<u16>

Maximum length in bytes (None = unlimited/MAX).

§

Blob

Unbounded binary data (BLOB / BYTEA).

§

Date

Date only (DATE).

§

Time

Time with optional precision (TIME(p)).

Fields

§precision: Option<u8>

Fractional seconds precision (None = default).

§

DateTime

Combined date and time (DATETIME — SQL Server legacy).

§

DateTime2

Combined date and time with precision (DATETIME2(p) — SQL Server).

Fields

§precision: Option<u8>

Fractional seconds precision (None = default).

§

Timestamp

Timestamp with optional precision (TIMESTAMP(p)).

Fields

§precision: Option<u8>

Fractional seconds precision (None = default).

§

TimestampTz

Timestamp with timezone and optional precision (TIMESTAMPTZ(p)).

Fields

§precision: Option<u8>

Fractional seconds precision (None = default).

§

Interval

Interval/duration (INTERVAL).

§

Boolean

Boolean (BOOLEAN — PostgreSQL, Snowflake, ClickHouse).

§

Bit

Bit (BIT — SQL Server).

§

Json

Text-based JSON (JSON — PostgreSQL).

§

Jsonb

Binary-optimized JSON (JSONB — PostgreSQL).

§

Variant

Semi-structured variant (VARIANT — Snowflake).

§

Uuid

UUID/GUID (UUID / UNIQUEIDENTIFIER).

§

Xml

XML data (XML).

§

Custom(String)

Custom type name (for types not covered by the enum variants).

Trait Implementations§

Source§

impl Clone for DataTypeRef

Source§

fn clone(&self) -> DataTypeRef

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 DataTypeRef

Source§

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

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

impl PartialEq for DataTypeRef

Source§

fn eq(&self, other: &DataTypeRef) -> 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 DataTypeRef

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, 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.