Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ modifyExternalTableProperties

pivotClause
: PIVOT XML?
LP_ aggregationFunction (AS? alias)? (COMMA_ aggregationFunction (AS? alias)?)* pivotForClause pivotInClause RP_
LP_ aggregationFunction (AS? alias)? (COMMA_ aggregationFunction (AS? alias)?)* pivotForClause pivotInClause RP_ alias?
;

pivotForClause
Expand All @@ -535,7 +535,7 @@ pivotInClauseExpr
;

unpivotClause
: UNPIVOT ((INCLUDE | EXCLUDE) NULLS)? LP_ columnNames pivotForClause unpivotInClause RP_
: UNPIVOT ((INCLUDE | EXCLUDE) NULLS)? LP_ (columnName | columnNames) pivotForClause unpivotInClause RP_ alias?
;

unpivotInClause
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,19 +676,24 @@
</select>

<select sql-case-id="select_pivot">
<projections start-index="7" stop-index="7">
<shorthand-projection start-index="7" stop-index="7"/>
<projections start-index="7" stop-index="18">
<shorthand-projection start-index="7" stop-index="18">
<owner name="pivotAlias" start-index="7" stop-index="16"/>
<actual-projections start-index="0" stop-index="0"/>
</shorthand-projection>
</projections>
<from>
<subquery-table start-index="14" stop-index="34" >
<from start-index="25" stop-index="104">
<subquery-table start-index="25" stop-index="45">
<subquery>
<select>
<projections start-index="22" stop-index="22">
<shorthand-projection start-index="22" stop-index="22"/>
</projections>
<from start-index="29" stop-index="33">
<simple-table name="sales" start-index="29" stop-index="33"/>
<from start-index="40" stop-index="44">
<simple-table name="sales" start-index="40" stop-index="44"/>
</from>
<projections start-index="33" stop-index="33">
<shorthand-projection start-index="33" stop-index="33">
<actual-projections start-index="0" stop-index="0"/>
</shorthand-projection>
</projections>
</select>
</subquery>
</subquery-table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<sql-case id="select_mod_function" value="SELECT MOD(order_id, 1) from t_order" db-types="PostgreSQL,openGauss" />
<sql-case id="select_sys_xml_agg" value="SELECT SYS_XMLAGG(SYS_XMLGEN(last_name)) XMLAGG FROM employees WHERE last_name LIKE 'R%' ORDER BY xmlagg;" db-types="Oracle" />
<sql-case id="select_set_function" value="SELECT customer_id, SET(cust_address_ntab) address FROM customers_demo ORDER BY customer_id;" db-types="Oracle" />
<sql-case id="select_pivot" value="SELECT * FROM (SELECT * FROM sales) PIVOT (SUM(amount) FOR (year, month) IN ((2018, 'Jan'), (2018, 'Feb')))" db-types="Oracle"/>
<sql-case id="select_pivot" value="SELECT pivotAlias.* FROM (SELECT * FROM sales) PIVOT (SUM(amount) FOR month IN ('Jan', 'Feb')) pivotAlias" db-types="Oracle"/>
<sql-case id="select_unpivot" value="SELECT * FROM (SELECT * FROM sales) UNPIVOT ((cert_type, cert_number) FOR cert_source IN ((primary_cert_type, primary_cert_no), (alt_cert_type1, alt_cert_no1), (alt_cert_type2, alt_cert_no2)))" db-types="Oracle"/>
<sql-case id="select_string_split_function" value="SELECT value as tag, COUNT(*) AS [number_of_articles] FROM Product CROSS APPLY STRING_SPLIT(Tags, ',') GROUP BY value HAVING COUNT(*) > 2 ORDER BY COUNT(*) DESC" db-types="SQLServer"/>
<sql-case id="select_from_open_json_function" value="SELECT * FROM OPENJSON(@array) WITH ( month VARCHAR(3), temp int, month_id tinyint '$.sql:identity()') as months" db-types="SQLServer"/>
Expand Down