Skip to content
Closed
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
11 changes: 9 additions & 2 deletions src/syntax/expr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,15 @@ export const exprMap: CstToDocMap<AllExprNodes> = {
}
},
paren_expr: (print, node, path) => {
// discard unnecessary nested ((parentheses))
if (isParenExpr(node.expr)) {
// discard unnecessary nested ((parentheses)),
// but not when the inner ones belong to a subquery or a row,
// as the outer ones may be required by the enclosing clause
if (
isParenExpr(node.expr) &&
!isSelectStmt(node.expr.expr) &&
!isCompoundSelectStmt(node.expr.expr) &&
!isListExpr(node.expr.expr)
) {
return print("expr");
}
// Discard unnecessary parenthesis around function arguments
Expand Down
7 changes: 7 additions & 0 deletions test/ddl/policy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ describe("policy", () => {
WITH CHECK (kind = 'public')
`);
});

it(`preserves parenthesis around subquery used as the USING condition`, async () => {
await testPostgresql(dedent`
CREATE POLICY admin_only ON permissions
USING ((SELECT is_admin FROM users WHERE name = current_user))
`);
});
});

describe("alter policy", () => {
Expand Down
Loading