pub fn parse_data_type(&mut self) -> Result<SQLType, ParserError> {
        match self.next_token() {
            Some(Token::Keyword(k)) => match k.to_uppercase().as_ref() {
                "BOOLEAN" => Ok(SQLType::Boolean),
                "FLOAT" => Ok(SQLType::Float(self.parse_optional_precision()?)),
                "REAL" => Ok(SQLType::Real),
                "DOUBLE" => {
                    if self.parse_keyword("PRECISION") {
                        Ok(SQLType::Double)
                    } else {
                        Ok(SQLType::Double)
                    }
                }
                "SMALLINT" => Ok(SQLType::SmallInt),
                "INT" | "INTEGER" => Ok(SQLType::Int),
                "BIGINT" => Ok(SQLType::BigInt),
                "VARCHAR" => Ok(SQLType::Varchar(self.parse_optional_precision()?)),
                "CHARACTER" => {
                    if self.parse_keyword("VARYING") {
                        Ok(SQLType::Varchar(self.parse_optional_precision()?))
                    } else {
                        Ok(SQLType::Char(self.parse_optional_precision()?))
                    }
                }
                "UUID" => Ok(SQLType::Uuid),
                "DATE" => Ok(SQLType::Date),
                "TIMESTAMP" => {
                    if self.parse_keyword("WITH") {
                        if self.parse_keywords(vec!["TIME", "ZONE"]) {
                            Ok(SQLType::Timestamp)
                        } else {
                            parser_err!(format!(
                                "Expecting 'time zone', found: {:?}",
                                self.peek_token()
                            ))
                        }
                    } else if self.parse_keyword("WITHOUT") {
                        if self.parse_keywords(vec!["TIME", "ZONE"]) {
                            Ok(SQLType::Timestamp)
                        } else {
                            parser_err!(format!(
                                "Expecting 'time zone', found: {:?}",
                                self.peek_token()
                            ))
                        }
                    } else {
                        Ok(SQLType::Timestamp)
                    }
                }
                "TIME" => {
                    if self.parse_keyword("WITH") {
                        if self.parse_keywords(vec!["TIME", "ZONE"]) {
                            Ok(SQLType::Time)
                        } else {
                            parser_err!(format!(
                                "Expecting 'time zone', found: {:?}",
                                self.peek_token()
                            ))
                        }
                    } else if self.parse_keyword("WITHOUT") {
                        if self.parse_keywords(vec!["TIME", "ZONE"]) {
                            Ok(SQLType::Time)
                        } else {
                            parser_err!(format!(
                                "Expecting 'time zone', found: {:?}",
                                self.peek_token()
                            ))
                        }
                    } else {
                        Ok(SQLType::Timestamp)
                    }
                }
                "REGCLASS" => Ok(SQLType::Regclass),
                "TEXT" => {
                    if let Ok(true) = self.consume_token(&Token::LBracket) {
                        self.consume_token(&Token::RBracket)?;
                        Ok(SQLType::Array(Box::new(SQLType::Text)))
                    } else {
                        Ok(SQLType::Text)
                    }
                }
                "BYTEA" => Ok(SQLType::Bytea),
                "NUMERIC" => {
                    let (precision, scale) = self.parse_optional_precision_scale()?;
                    Ok(SQLType::Decimal(precision, scale))
                }
                _ => parser_err!(format!("Invalid data type '{:?}'", k)),
            },
            Some(Token::Identifier(id)) => {
                if let Ok(true) = self.consume_token(&Token::Period) {
                    let ids = self.parse_tablename()?;
                    Ok(SQLType::Custom(format!("{}.{}", id, ids)))
                } else {
                    Ok(SQLType::Custom(id))
                }
            }
            other => parser_err!(format!("Invalid data type: '{:?}'", other)),
        }
    }
/// Parse a SQL datatype (in the context of a CREATE TABLE statement for example)
Parse a SQL datatype (in the context of a CREATE TABLE statement for example)
Parse a SQL datatype ( in the context of a CREATE TABLE statement for example )
pub fn parse_data_type(&mut self) -> Result<SQLType, ParserError> {
        match self.next_token() {
            Some(Token::Keyword(k)) => match k.to_uppercase().as_ref() {
                "BOOLEAN" => Ok(SQLType::Boolean),
                "FLOAT" => Ok(SQLType::Float(self.parse_optional_precision()?)),
                "REAL" => Ok(SQLType::Real),
                "DOUBLE" => {
                    if self.parse_keyword("PRECISION") {
                        Ok(SQLType::Double)
                    } else {
                        Ok(SQLType::Double)
                    }
                }
                "SMALLINT" => Ok(SQLType::SmallInt),
                "INT" | "INTEGER" => Ok(SQLType::Int),
                "BIGINT" => Ok(SQLType::BigInt),
                "VARCHAR" => Ok(SQLType::Varchar(self.parse_optional_precision()?)),
                "CHARACTER" => {
                    if self.parse_keyword("VARYING") {
                        Ok(SQLType::Varchar(self.parse_optional_precision()?))
                    } else {
                        Ok(SQLType::Char(self.parse_optional_precision()?))
                    }
                }
                "UUID" => Ok(SQLType::Uuid),
                "DATE" => Ok(SQLType::Date),
                "TIMESTAMP" => {
                    if self.parse_keyword("WITH") {
                        if self.parse_keywords(vec!["TIME", "ZONE"]) {
                            Ok(SQLType::Timestamp)
                        } else {
                            parser_err!(format!(
                                "Expecting 'time zone', found: {:?}",
                                self.peek_token()
                            ))
                        }
                    } else if self.parse_keyword("WITHOUT") {
                        if self.parse_keywords(vec!["TIME", "ZONE"]) {
                            Ok(SQLType::Timestamp)
                        } else {
                            parser_err!(format!(
                                "Expecting 'time zone', found: {:?}",
                                self.peek_token()
                            ))
                        }
                    } else {
                        Ok(SQLType::Timestamp)
                    }
                }
                "TIME" => {
                    if self.parse_keyword("WITH") {
                        if self.parse_keywords(vec!["TIME", "ZONE"]) {
                            Ok(SQLType::Time)
                        } else {
                            parser_err!(format!(
                                "Expecting 'time zone', found: {:?}",
                                self.peek_token()
                            ))
                        }
                    } else if self.parse_keyword("WITHOUT") {
                        if self.parse_keywords(vec!["TIME", "ZONE"]) {
                            Ok(SQLType::Time)
                        } else {
                            parser_err!(format!(
                                "Expecting 'time zone', found: {:?}",
                                self.peek_token()
                            ))
                        }
                    } else {
                        Ok(SQLType::Timestamp)
                    }
                }
                "REGCLASS" => Ok(SQLType::Regclass),
                "TEXT" => {
                    if let Ok(true) = self.consume_token(&Token::LBracket) {
                        self.consume_token(&Token::RBracket)?;
                        Ok(SQLType::Array(Box::new(SQLType::Text)))
                    } else {
                        Ok(SQLType::Text)
                    }
                }
                "BYTEA" => Ok(SQLType::Bytea),
                "NUMERIC" => {
                    let (precision, scale) = self.parse_optional_precision_scale()?;
                    Ok(SQLType::Decimal(precision, scale))
                }
                _ => parser_err!(format!("Invalid data type '{:?}'", k)),
            },
            Some(Token::Identifier(id)) => {
                if let Ok(true) = self.consume_token(&Token::Period) {
                    let ids = self.parse_tablename()?;
                    Ok(SQLType::Custom(format!("{}.{}", id, ids)))
                } else {
                    Ok(SQLType::Custom(id))
                }
            }
            other => parser_err!(format!("Invalid data type: '{:?}'", other)),
        }
    }
pub fn parse_data_type ( & mut self ) -> Result < SQLType , ParserError > { match self . next_token ( ) { Some ( Token :: Keyword ( k ) ) => match k . to_uppercase ( ) . as_ref ( ) { " " => Ok ( SQLType :: Boolean ) , " " => Ok ( SQLType :: Float ( self . parse_optional_precision ( ) ? ) ) , " " => Ok ( SQLType :: Real ) , " " => { if self . parse_keyword ( " " ) { Ok ( SQLType :: Double ) } else { Ok ( SQLType :: Double ) } } " " => Ok ( SQLType :: SmallInt ) , " " | " " => Ok ( SQLType :: Int ) , " " => Ok ( SQLType :: BigInt ) , " " => Ok ( SQLType :: Varchar ( self . parse_optional_precision ( ) ? ) ) , " " => { if self . parse_keyword ( " " ) { Ok ( SQLType :: Varchar ( self . parse_optional_precision ( ) ? ) ) } else { Ok ( SQLType :: Char ( self . parse_optional_precision ( ) ? ) ) } } " " => Ok ( SQLType :: Uuid ) , " " => Ok ( SQLType :: Date ) , " " => { if self . parse_keyword ( " " ) { if self . parse_keywords ( vec ! [ " " " " ] ) { Ok ( SQLType :: Timestamp ) } else { parser_err ! ( format ( " " self peek_token ( ) ) ) } } else if self . parse_keyword ( " " ) { if self . parse_keywords ( vec ! [ " " " " ] ) { Ok ( SQLType :: Timestamp ) } else { parser_err ! ( format ( " " self peek_token ( ) ) ) } } else { Ok ( SQLType :: Timestamp ) } } " " => { if self . parse_keyword ( " " ) { if self . parse_keywords ( vec ! [ " " " " ] ) { Ok ( SQLType :: Time ) } else { parser_err ! ( format ( " " self peek_token ( ) ) ) } } else if self . parse_keyword ( " " ) { if self . parse_keywords ( vec ! [ " " " " ] ) { Ok ( SQLType :: Time ) } else { parser_err ! ( format ( " " self peek_token ( ) ) ) } } else { Ok ( SQLType :: Timestamp ) } } " " => Ok ( SQLType :: Regclass ) , " " => { if let Ok ( true ) = self . consume_token ( & Token :: LBracket ) { self . consume_token ( & Token :: RBracket ) ? ; Ok ( SQLType :: Array ( Box :: new ( SQLType :: Text ) ) ) } else { Ok ( SQLType :: Text ) } } " " => Ok ( SQLType :: Bytea ) , " " => { let ( precision , scale ) = self . parse_optional_precision_scale ( ) ? ; Ok ( SQLType :: Decimal ( precision , scale ) ) } _ => parser_err ! ( format ( " " k ) ) , } , Some ( Token :: Identifier ( id ) ) => { if let Ok ( true ) = self . consume_token ( & Token :: Period ) { let ids = self . parse_tablename ( ) ? ; Ok ( SQLType :: Custom ( format ! ( " " id ids ) ) ) } else { Ok ( SQLType :: Custom ( id ) ) } } other => parser_err ! ( format ( " " other ) ) , } }
Parse a SQL datatype (in the context of a CREATE TABLE statement for example)
Parse a SQL datatype ( in the context of a CREATE TABLE statement for example )
&mut self
&mut self