Skip to main content

parse_type

Function parse_type 

Source
pub fn parse_type(type_str: &str) -> Result<DataType, TypeParseError>
Expand description

Parse a SQL type string into a DataType

Supports common SQL type names and aliases:

  • Numeric: INT, INTEGER, BIGINT, SMALLINT, FLOAT, DOUBLE, REAL, DECIMAL, NUMERIC
  • String: VARCHAR, CHAR, TEXT, STRING
  • Boolean: BOOLEAN, BOOL
  • Date/Time: DATE, TIME, TIMESTAMP, TIMESTAMPTZ, INTERVAL
  • Binary: BLOB, BYTEA, BINARY

ยงExamples

use smelt_types::parse_type;

let ty = parse_type("INTEGER").unwrap();
let ty = parse_type("VARCHAR(255)").unwrap();
let ty = parse_type("DECIMAL(10,2)").unwrap();
let ty = parse_type("TIMESTAMP WITH TIME ZONE").unwrap();