Skip to content

Commit 7ef9db9

Browse files
committed
add test & use parse_expr
1 parent 9ccbd73 commit 7ef9db9

2 files changed

Lines changed: 39 additions & 15 deletions

File tree

src/parser/mod.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13892,21 +13892,7 @@ impl<'a> Parser<'a> {
1389213892
None
1389313893
};
1389413894
self.expect_token(&Token::LParen)?;
13895-
let value = match self.peek_token_ref().token {
13896-
Token::LParen => {
13897-
// multi value column unpivot
13898-
Expr::Tuple(
13899-
self.parse_parenthesized_column_list(Mandatory, false)?
13900-
.into_iter()
13901-
.map(Expr::Identifier)
13902-
.collect(),
13903-
)
13904-
}
13905-
_ => {
13906-
// single value column unpivot
13907-
Expr::Identifier(self.parse_identifier()?)
13908-
}
13909-
};
13895+
let value = self.parse_expr()?;
1391013896
self.expect_keyword_is(Keyword::FOR)?;
1391113897
let name = self.parse_identifier()?;
1391213898
self.expect_keyword_is(Keyword::IN)?;

tests/sqlparser_common.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11101,6 +11101,44 @@ fn parse_unpivot_table() {
1110111101
verified_stmt(sql_unpivot_with_alias_and_multi_value).to_string(),
1110211102
sql_unpivot_with_alias_and_multi_value
1110311103
);
11104+
11105+
let sql_unpivot_with_alias_and_multi_value_and_qualifier = concat!(
11106+
"SELECT * FROM sales AS s ",
11107+
"UNPIVOT INCLUDE NULLS ((first_quarter, second_quarter) ",
11108+
"FOR half_of_the_year IN (",
11109+
"(sales.Q1, sales.Q2) AS H1, ",
11110+
"(sales.Q3, sales.Q4) AS H2",
11111+
"))"
11112+
);
11113+
11114+
if let Unpivot { columns, .. } =
11115+
&verified_only_select(sql_unpivot_with_alias_and_multi_value_and_qualifier).from[0].relation
11116+
{
11117+
assert_eq!(
11118+
*columns,
11119+
vec![
11120+
ExprWithAlias {
11121+
expr: Expr::Tuple(vec![
11122+
Expr::CompoundIdentifier(vec![Ident::new("sales"), Ident::new("Q1"),]),
11123+
Expr::CompoundIdentifier(vec![Ident::new("sales"), Ident::new("Q2"),]),
11124+
]),
11125+
alias: Some(Ident::new("H1")),
11126+
},
11127+
ExprWithAlias {
11128+
expr: Expr::Tuple(vec![
11129+
Expr::CompoundIdentifier(vec![Ident::new("sales"), Ident::new("Q3"),]),
11130+
Expr::CompoundIdentifier(vec![Ident::new("sales"), Ident::new("Q4"),]),
11131+
]),
11132+
alias: Some(Ident::new("H2")),
11133+
},
11134+
]
11135+
);
11136+
}
11137+
11138+
assert_eq!(
11139+
verified_stmt(sql_unpivot_with_alias_and_multi_value_and_qualifier).to_string(),
11140+
sql_unpivot_with_alias_and_multi_value_and_qualifier
11141+
);
1110411142
}
1110511143

1110611144
#[test]

0 commit comments

Comments
 (0)