Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- when a $1 or $$foo$$ is within () expression, like a function
  invocation, parse the $ as plain grammar piece
- add a test for this situation which does not parse otherwise
  and throws ParseException
  • Loading branch information
kwesterfeld2 committed Sep 23, 2024
1 parent 6f9b515 commit 83d991c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions driver/src/main/java/com/impossibl/postgres/jdbc/SQLText.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,12 @@ private static int consumeDollar(final String sql, final int start, final Compos
}
} while (++ndx < sql.length());

// Treat as a grammar piece of only one char if within paren expression
if (parent instanceof ParenGroupNode) {
parent.add(new GrammarPiece(sql.substring(start, start + 1), start));
return start + 1;
}

// Just treat as a grammar piece
parent.add(new GrammarPiece(sql.substring(start, ndx), start));
return ndx;
Expand Down
24 changes: 24 additions & 0 deletions driver/src/test/java/com/impossibl/postgres/jdbc/SQLTextTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,30 @@ public class SQLTextTests {
"--\n--",
"--\n--",
},
new String[] {
"PREPARE test_plan AS SELECT hashtext($1)",
"PREPARE test_plan AS SELECT hashtext($1)",
},
new String[] {
"PREPARE test_plan AS SELECT hashtext($$foo$$)",
"PREPARE test_plan AS SELECT hashtext($$foo$$)",
},
new String[] {
"PREPARE test_plan AS SELECT hashtext($$fo;o$$)",
"PREPARE test_plan AS SELECT hashtext($$fo;o$$)",
},
new String[] {
"select * from flatten('{\"a\":1,\"b\":2}', $ as root) as f",
"select * from flatten('{\"a\":1,\"b\":2}', $ as root) as f",
},
new String[] {
"call help ( $$ { me } $$ )",
"call help ( $$ { me } $$ )",
},
new String[] {
"call help ( $delim$ { me } $delim$ )",
"call help ( $delim$ { me } $delim$ )",
},
};

/**
Expand Down

0 comments on commit 83d991c

Please sign in to comment.