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
| Aspect | DataType | DataTypeRef |
|---|---|---|
| Use case | DDL generation | CAST / CONVERT expressions |
| Metadata | Full (encoding, precision, storage format) | Minimal (precision, scale, length) |
| Platform variants | Unified (one variant per type) | Separate (Decimal vs Numeric, DateTime vs DateTime2) |
| Collections | Array, Map, Struct | Not supported |
§Platform-Specific Variants
Some types have separate variants for platform-specific naming:
DecimalvsNumeric— equivalent in SQL, but some dialects prefer one over the otherDateTimevsDateTime2— SQL Server usesDATETIME2for precisionJsonvsJsonb—PostgreSQLdistinguishes between text and binary JSONBooleanvsBit— SQL Server usesBITfor 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)).
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.
Varchar
Variable-length character string (VARCHAR(n)).
Char
Fixed-length character string (CHAR(n)).
Text
Unbounded text type (TEXT).
NVarchar
Variable-length Unicode string (NVARCHAR(n) — SQL Server).
NChar
Fixed-length Unicode string (NCHAR(n) — SQL Server).
Binary
Fixed-length binary data (BINARY(n)).
VarBinary
Variable-length binary data (VARBINARY(n)).
Blob
Unbounded binary data (BLOB / BYTEA).
Date
Date only (DATE).
Time
Time with optional precision (TIME(p)).
DateTime
Combined date and time (DATETIME — SQL Server legacy).
DateTime2
Combined date and time with precision (DATETIME2(p) — SQL Server).
Timestamp
Timestamp with optional precision (TIMESTAMP(p)).
TimestampTz
Timestamp with timezone and optional precision (TIMESTAMPTZ(p)).
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
impl Clone for DataTypeRef
Source§fn clone(&self) -> DataTypeRef
fn clone(&self) -> DataTypeRef
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more