From eff92a2dc1ec429c65cb6ec6b80489740c92419c Mon Sep 17 00:00:00 2001 From: Nickolay Ponomarev Date: Fri, 11 Jan 2019 01:40:31 +0300 Subject: [PATCH] Remove special handling of ::type1::type2 from parse_pg_cast ...it gets handled just as well by the infix parser. (Add a test while we're at it.) --- src/sqlparser.rs | 12 +++--------- tests/sqlparser_postgres.rs | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/sqlparser.rs b/src/sqlparser.rs index 53d8000f..d0aa1fa3 100644 --- a/src/sqlparser.rs +++ b/src/sqlparser.rs @@ -227,16 +227,10 @@ impl Parser { /// Parse a postgresql casting style which is in the form of `expr::datatype` pub fn parse_pg_cast(&mut self, expr: ASTNode) -> Result { let _ = self.consume_token(&Token::DoubleColon)?; - let datatype = self.parse_data_type()?; - let pg_cast = ASTNode::SQLCast { + Ok(ASTNode::SQLCast { expr: Box::new(expr), - data_type: datatype, - }; - if let Some(Token::DoubleColon) = self.peek_token() { - self.parse_pg_cast(pg_cast) - } else { - Ok(pg_cast) - } + data_type: self.parse_data_type()?, + }) } /// Parse an expression infix (typically an operator) diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs index 57f9b69e..49619075 100644 --- a/tests/sqlparser_postgres.rs +++ b/tests/sqlparser_postgres.rs @@ -532,6 +532,20 @@ fn parse_create_table_from_pg_dump() { assert_eq!(SQLType::Varchar(Some(45)), c_first_name.data_type); assert_eq!(false, c_first_name.allow_null); + let c_create_date1 = &columns[8]; + assert_eq!( + Some(Box::new(ASTNode::SQLCast { + expr: Box::new(ASTNode::SQLCast { + expr: Box::new(ASTNode::SQLValue(Value::SingleQuotedString( + "now".to_string() + ))), + data_type: SQLType::Text + }), + data_type: SQLType::Date + })), + c_create_date1.default + ); + let c_release_year = &columns[10]; assert_eq!( SQLType::Custom("public.year".to_string()),