Skip to content

Commit

Permalink
fixes #608
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 11, 2024
1 parent 66f35ad commit f2a9fc1
Show file tree
Hide file tree
Showing 2 changed files with 22 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 @@ -313,6 +313,12 @@ private static int consumeParens(final String sql, final int start, final Deque<
}

private static int consumeDollar(final String sql, final int start, final CompositeNode parent) throws ParseException {

if (parent instanceof ParenGroupNode) {
parent.add(new GrammarPiece(sql.substring(start, start + 1), start));
return start + 1;
}

int ndx = start;
do {
if (lookAhead(sql, ndx) == '$') {
Expand Down
16 changes: 16 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,22 @@ 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",
},
};

/**
Expand Down

0 comments on commit f2a9fc1

Please sign in to comment.