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.)
This commit is contained in:
Nickolay Ponomarev 2019-01-11 01:40:31 +03:00
parent f21cd697c3
commit eff92a2dc1
2 changed files with 17 additions and 9 deletions

View file

@ -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<ASTNode, ParserError> {
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)

View file

@ -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()),