Skip to content

Commit eba0997

Browse files
jensensclaude
andcommitted
fix: double-parentheses for boolean cast in index suggestions
PostgreSQL requires double parentheses around cast expressions in CREATE INDEX: `((expr)::boolean)` not `(expr)::boolean`. The generated DDL failed with: syntax error at or near "::" Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b6ee968 commit eba0997

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

src/plone/pgcatalog/suggestions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def _btree_expr(field, idx_type):
7373
if idx_type == IndexType.DATE:
7474
return f"pgcatalog_to_timestamptz(idx->>'{field}')"
7575
if idx_type == IndexType.BOOLEAN:
76-
return f"(idx->>'{field}')::boolean"
76+
return f"((idx->>'{field}')::boolean)"
7777
if idx_type == IndexType.PATH:
7878
return f"(idx->>'{field}') text_pattern_ops"
7979
# FIELD, UUID — plain text expression

tests/test_suggestions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_boolean_uses_cast(self):
9090
registry = _reg(is_folderish=IndexType.BOOLEAN)
9191
result = suggest_indexes(["is_folderish"], registry, {})
9292
new = [s for s in result if s["status"] == "new"]
93-
assert any("::boolean" in s["ddl"] for s in new)
93+
assert any("((idx->>'is_folderish')::boolean)" in s["ddl"] for s in new)
9494

9595
def test_uuid_uses_text_expression(self):
9696
registry = _reg(UID=IndexType.UUID)

0 commit comments

Comments
 (0)