Skip to content

Commit 62189bc

Browse files
committed
ut
1 parent 12f8543 commit 62189bc

File tree

2 files changed

+70
-5
lines changed

2 files changed

+70
-5
lines changed

src/parser/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13841,11 +13841,11 @@ impl<'a> Parser<'a> {
1384113841
let aggregate_functions = self.parse_comma_separated(Self::parse_aliased_function_call)?;
1384213842
self.expect_keyword_is(Keyword::FOR)?;
1384313843
let value_column = if self.peek_token_ref().token == Token::LParen {
13844-
self.parse_parenthesized_compound_identifier_list(Mandatory, false)?
13844+
self.parse_parenthesized_column_list_inner(Mandatory, false, |p| {
13845+
p.parse_subexpr(self.dialect.prec_value(Precedence::Between))
13846+
})?
1384513847
} else {
13846-
vec![Expr::CompoundIdentifier(
13847-
self.parse_period_separated(|p| p.parse_identifier())?,
13848-
)]
13848+
vec![self.parse_subexpr(self.dialect.prec_value(Precedence::Between))?]
1384913849
};
1385013850
self.expect_keyword_is(Keyword::IN)?;
1385113851

tests/sqlparser_common.rs

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10925,6 +10925,71 @@ fn parse_pivot_table() {
1092510925
verified_stmt(sql_without_table_alias).to_string(),
1092610926
sql_without_table_alias
1092710927
);
10928+
10929+
let multiple_value_columns_sql = concat!(
10930+
"SELECT * FROM person ",
10931+
"PIVOT(",
10932+
"SUM(age) AS a, AVG(class) AS c ",
10933+
"FOR (name, age) IN (('John', 30) AS c1, ('Mike', 40) AS c2))",
10934+
);
10935+
10936+
assert_eq!(
10937+
verified_only_select(multiple_value_columns_sql).from[0].relation,
10938+
Pivot {
10939+
table: Box::new(TableFactor::Table {
10940+
name: ObjectName::from(vec![Ident::new("person")]),
10941+
alias: None,
10942+
args: None,
10943+
with_hints: vec![],
10944+
version: None,
10945+
partitions: vec![],
10946+
with_ordinality: false,
10947+
json_path: None,
10948+
sample: None,
10949+
index_hints: vec![],
10950+
}),
10951+
aggregate_functions: vec![
10952+
ExprWithAlias {
10953+
expr: call("SUM", [Expr::Identifier(Ident::new("age"))]),
10954+
alias: Some(Ident::new("a"))
10955+
},
10956+
ExprWithAlias {
10957+
expr: call("AVG", [Expr::Identifier(Ident::new("class"))]),
10958+
alias: Some(Ident::new("c"))
10959+
},
10960+
],
10961+
value_column: vec![
10962+
Expr::Identifier(Ident::new("name")),
10963+
Expr::Identifier(Ident::new("age")),
10964+
],
10965+
value_source: PivotValueSource::List(vec![
10966+
ExprWithAlias {
10967+
expr: Expr::Tuple(vec![
10968+
Expr::Value(
10969+
(Value::SingleQuotedString("John".to_string())).with_empty_span()
10970+
),
10971+
Expr::Value((Value::Number("30".into(), false)).with_empty_span()),
10972+
]),
10973+
alias: Some(Ident::new("c1"))
10974+
},
10975+
ExprWithAlias {
10976+
expr: Expr::Tuple(vec![
10977+
Expr::Value(
10978+
(Value::SingleQuotedString("Mike".to_string())).with_empty_span()
10979+
),
10980+
Expr::Value((Value::Number("40".into(), false)).with_empty_span()),
10981+
]),
10982+
alias: Some(Ident::new("c2"))
10983+
},
10984+
]),
10985+
default_on_null: None,
10986+
alias: None,
10987+
}
10988+
);
10989+
assert_eq!(
10990+
verified_stmt(multiple_value_columns_sql).to_string(),
10991+
multiple_value_columns_sql
10992+
);
1092810993
}
1092910994

1093010995
#[test]
@@ -11146,7 +11211,7 @@ fn parse_pivot_unpivot_table() {
1114611211
expr: call("sum", [Expr::Identifier(Ident::new("population"))]),
1114711212
alias: None
1114811213
}],
11149-
value_column: vec![Expr::CompoundIdentifier(vec![Ident::new("year")])],
11214+
value_column: vec![Expr::Identifier(Ident::new("year"))],
1115011215
value_source: PivotValueSource::List(vec![
1115111216
ExprWithAlias {
1115211217
expr: Expr::Value(

0 commit comments

Comments
 (0)