Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Plsql] pivot_clause and unpivot_clause can have own alias #4363

Merged
merged 1 commit into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sql/plsql/PlSqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -5988,7 +5988,7 @@ flashback_query_clause
;

pivot_clause
: PIVOT XML? '(' pivot_element (',' pivot_element)* pivot_for_clause pivot_in_clause ')'
: PIVOT XML? '(' pivot_element (',' pivot_element)* pivot_for_clause pivot_in_clause ')' table_alias?
;

pivot_element
Expand All @@ -6013,7 +6013,7 @@ pivot_in_clause_elements
;

unpivot_clause
: UNPIVOT ((INCLUDE | EXCLUDE) NULLS)? '(' (column_name | paren_column_list) pivot_for_clause unpivot_in_clause ')'
: UNPIVOT ((INCLUDE | EXCLUDE) NULLS)? '(' (column_name | paren_column_list) pivot_for_clause unpivot_in_clause ')' table_alias?
;

unpivot_in_clause
Expand Down
9 changes: 9 additions & 0 deletions sql/plsql/examples/pivot14.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SELECT s2.id, name, subject, score
FROM scores2 s1
UNPIVOT (
score FOR subject IN (
chinese_score AS 'Chinese',
math_score AS 'Math',
english_score AS 'English'
)
) s2;
6 changes: 6 additions & 0 deletions sql/plsql/examples/pivot15.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT *
FROM (SELECT id, name, subject, score FROM scores) s1
PIVOT (
MAX(score)
FOR subject IN ('Chinese', 'Math', 'English')
) s2;
Loading