Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Addressing PR Review comments. Using existing WITH and OFFSET keyword…
…s, adding ORDINALITY keyword.
  • Loading branch information
David Hayes committed Apr 8, 2025
commit 6549bcbd604513a56ac64c73d25953c994dfedff
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public class ParserKeywordsUtils {
{"OPTIMIZE", RESTRICTED_ALIAS},
{"OR", RESTRICTED_SQL2016},
{"ORDER", RESTRICTED_SQL2016},
{"ORDINALITY", RESTRICTED_SQL2016},
{"OUTER", RESTRICTED_JSQLPARSER},
{"OUTPUT", RESTRICTED_JSQLPARSER},
{"OPTIMIZE ", RESTRICTED_JSQLPARSER},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public StringBuilder appendTo(StringBuilder builder) {
builder.append(function.toString());

if (withClause != null) {
builder.append(" ").append(withClause);
builder.append(" WITH ").append(withClause);
}

if (alias != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ public <S> StringBuilder visit(TableFunction tableFunction, S context) {
tableFunction.getFunction().accept(this.expressionVisitor, context);

if (tableFunction.getWithClause() != null) {
builder.append(" ").append(tableFunction.getWithClause());
builder.append(" WITH ").append(tableFunction.getWithClause());
}

if (tableFunction.getAlias() != null) {
Expand Down
5 changes: 2 additions & 3 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
| <K_OR:"OR">
| <K_ORACLE_NAMED_PARAMETER_ASSIGNMENT: "=>">
| <K_ORDER:"ORDER">
| <K_ORDINALITY:"ORDINALITY">
| <K_OUTER:"OUTER">
| <K_OUTPUT:"OUTPUT">
| <K_OVER:"OVER">
Expand Down Expand Up @@ -545,8 +546,6 @@ TOKEN: /* SQL Keywords. prefixed with K_ to avoid name clashes */
| <K_WHERE:"WHERE">
| <K_WINDOW:"WINDOW">
| <K_WITH:"WITH">
| <K_WITH_OFFSET:"WITH OFFSET">
| <K_WITH_ORDINALITY:"WITH ORDINALITY">
| <K_WITH_TIES:"WITH TIES">
| <K_WITHIN:"WITHIN">
| <K_WITHOUT:"WITHOUT">
Expand Down Expand Up @@ -6643,7 +6642,7 @@ TableFunction TableFunction():
{
[ prefix = <K_LATERAL> ]
function=Function()
[ withClause = <K_WITH_OFFSET> | withClause = <K_WITH_ORDINALITY> ]
[ <K_WITH> ( withClause = <K_OFFSET> | withClause = <K_ORDINALITY> ) ]
{
return prefix!=null
? withClause!=null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ void testTableFunctionWithNamedParameterWhereNameIsOuterKeyword() throws JSQLPar

@ParameterizedTest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@ValueSource(strings = {
"WITH OFFSET",
"WITH ORDINALITY"
"OFFSET",
"ORDINALITY"
})
void testTableFunctionWithSupportedWithClauses(String withClause) throws JSQLParserException {
String sqlStr = "SELECT * FROM UNNEST(ARRAY[1, 2, 3]) " + withClause + " AS t(a, b)";
String sqlStr = "SELECT * FROM UNNEST(ARRAY[1, 2, 3]) WITH " + withClause + " AS t(a, b)";
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}
}